Package com.mockturtlesolutions.snifflib.datatypes

Examples of com.mockturtlesolutions.snifflib.datatypes.DblMatrix


             
          }
        });
   
    DblParamSet temp = new DblParamSet();
    temp.setParam("Hey",new DblMatrix(1.0));
    temp.setParam("There",new DblMatrix(2.0));
   
    this.priorEditor.setParamSet(temp);
       
    //this.parameterEditor 
   
View Full Code Here


    pars2 = currentEditor.getParamSet();
    Vector persistentParams = backingBuffer.getPersistentParametersForDescriptor(descriptor);
    for (int j=0;j<persistentParams.size();j++)
    {
      PersistentParameter pp = (PersistentParameter)persistentParams.get(j);
      pars.setParam(pp.getName(),new DblMatrix(new Double(pp.getValue())));
      pars2.setParam(pp.getName(),new DblMatrix(new Double(pp.getValue())))
    }
   
   
    descriptor = "prior";
    pars = priorEditor.getParamSet();
    persistentParams = backingBuffer.getPersistentParametersForDescriptor(descriptor);
    for (int j=0;j<persistentParams.size();j++)
    {
      PersistentParameter pp = (PersistentParameter)persistentParams.get(j);
      pars.setParam(pp.getName(),new DblMatrix(new Double(pp.getValue())))
    }
   
   
    descriptor = "mixing";
    pars = proposalEditor.getParamSet();
    persistentParams = backingBuffer.getPersistentParametersForDescriptor(descriptor);
    for (int j=0;j<persistentParams.size();j++)
    {
      PersistentParameter pp = (PersistentParameter)persistentParams.get(j);
      pars.setParam(pp.getName(),new DblMatrix(new Double(pp.getValue())))
    }
   
    descriptor = "configuration";
    persistentParams = backingBuffer.getPersistentParametersForDescriptor(descriptor);
    for (int j=0;j<persistentParams.size();j++)
View Full Code Here

   
    if (descriptor.equals("parameter"))
    {
      System.out.println("Adding parameter");
      pars = parameterEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(0.0));
      parameterEditor.setParamSet(pars);
     
      pars = currentEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(0.0));
      currentEditor.setParamSet(pars);
    }
    else if (descriptor.equals("prior"))
    {
      System.out.println("Adding prior");
      pars = priorEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(0.0));
      priorEditor.setParamSet(pars);
    }
    else if (descriptor.equals("mixing"))
    {
      System.out.println("Adding mixing");
      pars = proposalEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(0.0));
      proposalEditor.setParamSet(pars);
    }
    else if (descriptor.equals("configuration"))
    {
      System.out.println("Adding configuration");
View Full Code Here

    DblParamSet pars = null;
   
    if (descriptor.equals("parameter"))
    {
      pars = parameterEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(new Double(val)));
      parameterEditor.setParamSet(pars);
     
      pars = currentEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(new Double(val)));
      currentEditor.setParamSet(pars);
     
    }
   
    if (descriptor.equals("prior"))
    {
      pars = priorEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(new Double(val)));
      priorEditor.setParamSet(pars);
    }
   
    if (descriptor.equals("mixing"))
    {
      pars = proposalEditor.getParamSet();
      pars.setParam(parametername,new DblMatrix(new Double(val)));
      proposalEditor.setParamSet(pars);
     
    }
   
    if (descriptor.equals("configuration"))
View Full Code Here

      pars = parameterEditor.getParamSet();
      params = pars.parameterSet();
   
      for (int j=0;j<params.length;j++)
      {
        DblMatrix val = pars.getParam(params[j]);
        outSet.add(new PersistentParameter(params[j],descriptor,val.getDoubleAt(0).toString()));
      }
    }
   
   
    if (descript.equals("prior"))
    {
   
      descriptor = "prior";
     
      pars = priorEditor.getParamSet();
      params = pars.parameterSet();
     
      for (int j=0;j<params.length;j++)
      {
        DblMatrix val = pars.getParam(params[j]);
        outSet.add(new PersistentParameter(params[j],descriptor,val.getDoubleAt(0).toString()));
      }
    }
   
    if (descript.equals("mixing"))
    {
   
      descriptor = "mixing";
      pars = proposalEditor.getParamSet();
      params = pars.parameterSet();

      for (int j=0;j<params.length;j++)
      {
        DblMatrix val = pars.getParam(params[j]);
        outSet.add(new PersistentParameter(params[j],descriptor,val.getDoubleAt(0).toString()));
      }
    }
   
    if (descript.equals("configuration"))
    {
View Full Code Here

      System.out.println("There are no parameters.");
    }
   
    for (int j=0;j<params.length;j++)
    {
      DblMatrix val = pars.getParam(params[j]);
      outSet.add(new PersistentParameter(params[j],descriptor,val.getDoubleAt(0).toString()));
    }
   
    descriptor = "prior";
    pars = priorEditor.getParamSet();
    params = pars.parameterSet();
   
    for (int j=0;j<params.length;j++)
    {
      DblMatrix val = pars.getParam(params[j]);
      outSet.add(new PersistentParameter(params[j],descriptor,val.getDoubleAt(0).toString()));
    }
   
    descriptor = "mixing";
    pars = proposalEditor.getParamSet();
    params = pars.parameterSet();
   
    for (int j=0;j<params.length;j++)
    {
      DblMatrix val = pars.getParam(params[j]);
      outSet.add(new PersistentParameter(params[j],descriptor,val.getDoubleAt(0).toString()));
    }
   
    descriptor = "configuration";
    HashMap configmap = this.configurationMap;
    Set pnames = configurationMap.keySet();
View Full Code Here

      {

        if (pname.startsWith("sigmaCb")) //Concentrations can not be negative!!
        {
          this.prop.setLogNormal(pname);
          this.prop.setMixingParam(pname,new DblMatrix(0.01));
        }
        else
        {
          this.prop.setLogNormal(pname);
          this.prop.setMixingParam(pname,new DblMatrix(0.001));
        }
      }
      else if (pname.startsWith("T#")) //Concentrations can not be negative!!
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.startsWith("TExpSSdev")) //Volume deviations can not be negative!!
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.startsWith("C#")) //
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.001));
      }
      else if (pname.startsWith("CExpdev")) //
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.startsWith("CExpSSdev")) //
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.startsWith("Vo#")) //Volumes added can not be negative!!
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.00001));
      }
      else if (pname.startsWith("v#")) //Volumes added can not be negative!!
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.001));
      }
      else if (pname.contains("pKa#")) //From order-restricted inference on the pKa's
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.01));
      }
      else if (pname.contains("pKb#")) //From order-restricted inference on the pKa's
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.01));
      }
      else if (pname.contains("pKadiff")) //From order-restricted inference on the pKa's
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.005));
      }
      else if (pname.contains("pKbdiff")) //From order-restricted inference on the pKb's
      {
        this.prop.setLogNormal(pname);
        this.prop.setMixingParam(pname,new DblMatrix(0.0005));
      }
      else if (pname.contains("interceptpH")) //Latent pH link parameter
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.contains("linearpH")) //Latent pH link parameter
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.contains("quadraticpH")) //Latent pH link parameter
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.0001));
      }
      else if (pname.contains("cubicpH")) //Latent pH link parameter.  Solution tends to be sensitive to this so take to be smaller than other link parameters.
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.00001));
      }
      else if (pname.contains("smoothing"))
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.001));
      }
      else if (pname.contains("pH"))
      {
        this.prop.setMixingParam(pname,new DblMatrix(0.001));
      }
      else
      {
        DblMatrix VALUE = DblMatrix.abs(like.getParam(pname));
        if (DblMatrix.test(VALUE.eq(0.0)))
        {
          VALUE = new DblMatrix(0.000001);
        }
        else
        VALUE = VALUE.times(0.000001);
        }

        this.prop.setMixingParam(pname,VALUE);

      }
View Full Code Here

      exp = (String)experiments.get(k);
      subsamples = this.parent.getTitrationSubsampleIDs(exp);

      //Make an overlay plot of the cummulative sum of Conc_i*Volume_Added_i versus pH_i
     
      DblMatrix cv_total = new DblMatrix(0.0);
      DblMatrix v_total = new DblMatrix(0.0);
      //Plot plot = new Plot(data);
      //plot.setOverlay(true);
      boolean NANSENCOUNTERED = false;
      int NANLINE = 0;
      String NANSUB = "";
      String NANEXP = "";
     
      for (int ss=0;ss<subsamples.size();ss++)
      {

        String ssid = (String)subsamples.get(ss);
        cv_total = new DblMatrix(0.0);
        v_total = new DblMatrix(new Double(this.parent.getInitialVolume(exp,ssid)));


        //data.addColumn("pH"+ssid,Double.class);
        //data.addColumn("CV"+ssid,Double.class);
        //plot.addResponseVariable("CV"+ssid);
        //plot.addPredictorVariable("pH"+ssid);

        Vector observations = this.parent.getTitrationObservationNumbers(exp,ssid);
        for (int obs=0;obs<observations.size();obs++)
        {

          String obsnum = (String)observations.get(obs);
          String val;
          Double nval;
         
          val = this.parent.getTitrantConcentration(exp,ssid,obsnum);
          try
          {
            nval = new Double(val);
          }
          catch(Exception err)
          {
            NANSENCOUNTERED = true;
            NANLINE = obs;
            NANSUB = ssid;
            NANEXP = exp;
           
            nval = new Double(Double.NaN);
          }
          Double conc = nval;
          //Double conc = new Double(this.parent.getTitrantConcentration(exp,ssid,obsnum));
          val = this.parent.getVolumeAdded(exp,ssid,obsnum);
          try
          {
            nval = new Double(val);
          }
          catch(Exception err)
          {
            NANSENCOUNTERED = true;
            NANLINE = obs;
            NANSUB = ssid;
            NANEXP = exp;
            nval = new Double(Double.NaN);
          }
          Double volAdded = nval;
          //Double volAdded = new Double(this.parent.getVolumeAdded(exp,ssid,obsnum));
         
          cv_total = cv_total.plus(conc.doubleValue()*volAdded.doubleValue());
          v_total = v_total.plus(volAdded.doubleValue());
         
         
         
          //System.out.println("conc"+conc);
          //System.out.println("volAdded"+volAdded);
View Full Code Here

    Integer occurances;
    int count;
    Double vol = null;
    Double val = null;
    Double pHval = null;
    DblMatrix Cbval,Cbcont,Cblof,Cbplot,currentConc;
    String conc,titrant,voladded;
    double total_vol = 0.0;
    String totVol;
   
   
    int nrows = this.outSet.getRowCount();
    while (this.outSet.getRowCount() > 0)
    {
      this.outSet.removeRow(0);
     
    }

    this.outSet.fireTableRowsDeleted(0,nrows-1);

   
    int outrow=0;
    // Get an average Contained for each experiment (average over the subsamples). (Done)
    // Calculate Cb separately for each titration subsample.
    // Pool Cb for all Subsamples and all experiments
    // Throw a smooth curve through the negative Cb.
    // Subtract the contribution to the total Cb due to titrant(s)
    // as they were added.
    // Plot this versus pH with circles(data);
    //
   
   
    
   
    for (int exp=0;exp<experiments.size();exp++)
    {
      expname = (String)experiments.get(exp);
     
      /// Calculate average contained...///
      containedSOL = new BufferSolution();//This will include water.
     
      subsamples = this.parent.getContainedSubsampleIDs(expname);
     
     
      Navg = new HashMap();
     
      for (int sub=0;sub<subsamples.size();sub++)
      { 
        //newSol will contain the contains for just this subsample.
        //To protect against multiple entries or situations in
        //which a complex buffer that consists of a mixture of
        //simple buffers already in the contained etc. we create
        //the solution first. Then we examime for the entries in
        //the final solution. We add a 1 to the integer stored in
        //Navg for that buffer. Note that the add method of BufferSolution
        //resolves all mixture type buffers to their simpliest elements.
        newSol = new BufferSolution();
       
        subsample = (String)subsamples.get(sub);
        observations = this.parent.getContainedObservationNumbers(expname,subsample);
        for (int obs=0;obs<observations.size();obs++)
        {
          obsnum = (String)observations.get(obs);
          contained = this.parent.getContainedNickname(expname,subsample,obsnum);
          conc = this.parent.getContainedConcentration(expname,subsample,obsnum);
         
          try
          {
                              n = new Double(nf.parse(conc).doubleValue());
                      }
          catch (ParseException ex)
          {
            System.err.println("Problem parsing concentration "+conc+".");
                             
                      }
 
          newSol.add(contained,n);
        }
       
        //System.out.println("We are here");
        //Alright now we include instance counts into our running total of instances.
        //contents = newSol.getContents();
        //Set cnts = contents.keySet();
        //Iterator iter = cnts.iterator();
        //while (iter.hasNext())
       
        contents = newSol.getComponents();
       
       
        for (int m=0;m<contents.length;m++)
        {
         
          //nickname = (String)iter.next();
          nickname = contents[m];
          if (Navg.containsKey(nickname))
          {
            occurances = (Integer)Navg.get(nickname);
            count = occurances.intValue();
          }
          else
          {
            count = 0;
           
          }
          Navg.put(nickname,new Integer(count+1))
        }
        //addSol differs from mixSol in that mixSol assumes mutual
        //dilution from mixing in certain ratios.  addSol simply
        //adds concentrations.
        containedSOL = BufferSolution.addSol(containedSOL,newSol);
      }
     
     
      //Calculate the average concentration of each contained from the sums formulated
      //above.
      if (contents != null)
      {
        //Set cnts = contents.keySet();
        //Iterator iter = cnts.iterator();
        //Calculate the average concentration of each contained.
        //while (iter.hasNext())
       
        for (int m=0;m<contents.length;m++)
        {
          //nickname = (String)iter.next();
          nickname = contents[m];
          occurances = (Integer)Navg.get(nickname);
          count = occurances.intValue();
          DblMatrix v = containedSOL.getConcentration(nickname);
          //val = (Double)((DblMatrix)contents.get(nickname)).getDoubleAt(0);
          containedSOL.setConcentration(nickname,v.divideBy(count));
          //contents.put(nickname,val.doubleValue()/count);
        }
      }
     
      //containedSOL is now a solution consisting of all stated components
      //set at their average value, where the average was taken over all
      //subsamples in which that component made an appearance.  In other
      //words the total number of subsamples is not necessarily the normalizing
      //value in the average for a particular component.
     
     
     
      /////////////////////////////////////
     
      subsamples = this.parent.getTitrationSubsampleIDs(expname);
     
      for (int sub=0;sub<subsamples.size();sub++)
      {
        subsample = (String)subsamples.get(sub);
        //Start with a new buffer solution for this titration.
        titrationSol = new BufferSolution();
        titrationSol = BufferSolution.addSol(titrationSol,containedSOL);//Put the (avg.) contained stuff in.
       
        observations = this.parent.getTitrationObservationNumbers(expname,subsample);
       
        totVol = (String)this.parent.getInitialVolume(expname,subsample);
       
       
        try
        {
                            total_vol = nf.parse(totVol).doubleValue();
         

                    }
        catch (ParseException ex)
        {
          System.err.println("Problem parsing total volume "+totVol+".");

                    }
         
       
        for (int obs=0;obs<observations.size();obs++)
        {
          obsnum = (String)observations.get(obs);
          titrant = this.parent.getTitrant(expname,subsample,obsnum);
          conc = this.parent.getTitrantConcentration(expname,subsample,obsnum);
          voladded = this.parent.getVolumeAdded(expname,subsample,obsnum);
          try
          {
                              n = new Double(nf.parse(conc).doubleValue());
           
                      }
          catch (ParseException ex)
          {
            System.err.println("Problem parsing concentration "+conc+".");
                             
                      }
         
          pH = this.parent.getpH(expname,subsample,obsnum);
          try
          {
                              pHval = new Double(nf.parse(pH).doubleValue());
           
                      }
          catch (ParseException ex)
          {
            System.err.println("Problem parsing concentration "+conc+".");
                             
                      }
         
         
          try
          {
                              vol = new Double(nf.parse(voladded).doubleValue());
           
                      }
          catch (ParseException ex)
          {
            System.err.println("Problem parsing volume added "+voladded+".");
                             
                      }
         
          currentConc = titrationSol.getConcentration(titrant);
          if (currentConc == null)
          {
            currentConc = new DblMatrix(0.0);
          }
         
          currentConc  = ((currentConc.times(total_vol)).plus(n*vol))
          total_vol = total_vol+vol;
          currentConc  = currentConc.divideBy(total_vol);
          titrationSol.setConcentration(titrant,currentConc);
          //System.out.println("titrant is"+titrant);
          //titrationSol.show("titrationSol");
          //Get adjustment coefficients using titrationSol
          //AdjCoef adj = new AdjCoef(titrationSol,pHval);
          CB = titrationSol.Cb(new DblMatrix(pHval),true);
          //System.out.println("OK till here ");
          Cbval = (DblMatrix)CB.get("total");
         
          //System.out.println("OK till here youare");
          DblMatrix CbNaOH = (DblMatrix)CB.get("com.mockturtlesolutions.NaOH");
          if (CbNaOH == null)
          {
            System.out.println("CbNaOH is null");
          }
         
          //CbNaOH.show("CbNaOH");
          //Cbval.show("Cbval");
          //Because of additivity we can subtract
          CB = containedSOL.Cb(new DblMatrix(pHval));
          Cbcont = (DblMatrix)CB.get("total");
          //Cbcont.show("Cbcont");
         
          //titrationSol.show("titrationSol");
          //containedSOL.show("containedSol");
View Full Code Here

      Lpreg FUNC = ((LpregBufferPredictor)this.predictor).getLpreg();
      //Update parts of the gui.

      AbstractBandwidthMethod BW = FUNC.getBandwidthMethod();
      AbstractSmoothMethod SM = BW.getSmoothMethod();
      DblMatrix param = null;
      param = SM.getSmoothParameter(FUNC,param);

      int i=0;
      while (i<this.smoothParamMethods.length)
      {
        if (this.smoothParamMethods[i].equals("fixed"))
        {
          break;
        }
        i++;
      }
      this.smoothParamMethodSelector.setSelectedIndex(i);


      DblMatrix model = FUNC.getModel();
      this.polynomialOrder.setSelectedIndex(model.getN()-1);
      this.smoothParamText.setText(param.getDoubleAt(0).toString());

      //Updat the fit line.

      DblMatrix[] XData = FUNC.getXdata();
      DblMatrix YData = FUNC.getYdata();

      Min m = new Min(this.outSet);
      m.addResponseVariable("pH");
      m.run();
      DataSet minpH = m.getResult();
      DblMatrix min = new DblMatrix((Double)minpH.getValueAt(0,1));

      Max mx = new Max(this.outSet);
      mx.addResponseVariable("pH");
      mx.run();
      DataSet maxpH = mx.getResult();
      DblMatrix max = new DblMatrix((Double)maxpH.getValueAt(0,1));

      // Get widest range based on lpreg's internal data and the current data.
      //Yes, those two data sets may be different after some time!
      min = DblMatrix.min(min,XData[0].min());
      max = DblMatrix.max(max,XData[0].max());
      //

      DblMatrix xx[] = new DblMatrix[1];
      xx[0] = DblMatrix.span(min,max,2*outSet.getRowCount());

                  DblMatrix yy = FUNC.predict(xx);
                  if (this.fitline == null)
      {
        this.fitline = new SLLine(plotPanel.getAxes());
        this.fitline.setMarkerType(8);
        this.fitline.setLineColor(Color.red);
View Full Code Here

TOP

Related Classes of com.mockturtlesolutions.snifflib.datatypes.DblMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.