Package weka.core.matrix

Examples of weka.core.matrix.DoubleVector


    X.lsqrSelection( Y, pvt, 1 );
    X.positiveDiagonal( Y, pvt );
   
    PaceMatrix sol = (PaceMatrix) Y.clone();
    X.rsolve( sol, pvt, pvt.size() );
    DoubleVector r = Y.getColumn( pvt.size(), n-1, 0);
    double sde = Math.sqrt(r.sum2() / r.size());
   
    DoubleVector aHat = Y.getColumn( 0, pvt.size()-1, 0).times( 1./sde );

    DoubleVector aTilde = null;
    switch( paceEstimator) {
    case ebEstimator:
    case nestedEstimator:
    case subsetEstimator:
      NormalMixture d = new NormalMixture();
      d.fit( aHat, MixtureDistribution.NNMMethod );
      if( paceEstimator == ebEstimator )
  aTilde = d.empiricalBayesEstimate( aHat );
      else if( paceEstimator == ebEstimator )
  aTilde = d.subsetEstimate( aHat );
      else aTilde = d.nestedEstimate( aHat );
      break;
    case pace2Estimator:
    case pace4Estimator:
    case pace6Estimator:
      DoubleVector AHat = aHat.square();
      ChisqMixture dc = new ChisqMixture();
      dc.fit( AHat, MixtureDistribution.NNMMethod );
      DoubleVector ATilde;
      if( paceEstimator == pace6Estimator )
  ATilde = dc.pace6( AHat );
      else if( paceEstimator == pace2Estimator )
  ATilde = dc.pace2( AHat );
      else ATilde = dc.pace4( AHat );
      aTilde = ATilde.sqrt().times( aHat.sign() );
      break;
    case olsEstimator:
      aTilde = aHat.copy();
      break;
    case aicEstimator:
    case bicEstimator:
    case ricEstimator:
    case olscEstimator:
      if(paceEstimator == aicEstimator) olscThreshold = 2;
      else if(paceEstimator == bicEstimator) olscThreshold = Math.log( n );
      else if(paceEstimator == ricEstimator) olscThreshold = 2*Math.log( kr );
      aTilde = aHat.copy();
      for( int i = 0; i < aTilde.size(); i++ )
  if( Math.abs(aTilde.get(i)) < Math.sqrt(olscThreshold) )
    aTilde.set(i, 0);
    }
    PaceMatrix YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
    X.rsolve( YTilde, pvt, pvt.size() );
    DoubleVector betaTilde = YTilde.getColumn(0).unpivoting( pvt, kr );
   
    return betaTilde.getArrayCopy();
  }
View Full Code Here


    //make a copy of the array
    double []disCopy = new double[distance.length];
    for (int i=0;i<distance.length; i++)
      disCopy[i]= distance[i];

    DoubleVector sortVector = new DoubleVector(disCopy);
    sortVector.sort();
    sorted = sortVector.getArrayCopy();
    return sorted;
  }
View Full Code Here

    X.lsqrSelection( Y, pvt, 1 );
    X.positiveDiagonal( Y, pvt );
   
    PaceMatrix sol = (PaceMatrix) Y.clone();
    X.rsolve( sol, pvt, pvt.size() );
    DoubleVector r = Y.getColumn( pvt.size(), n-1, 0);
    double sde = Math.sqrt(r.sum2() / r.size());
   
    DoubleVector aHat = Y.getColumn( 0, pvt.size()-1, 0).times( 1./sde );

    DoubleVector aTilde = null;
    switch( paceEstimator) {
    case ebEstimator:
    case nestedEstimator:
    case subsetEstimator:
      NormalMixture d = new NormalMixture();
      d.fit( aHat, MixtureDistribution.NNMMethod );
      if( paceEstimator == ebEstimator )
  aTilde = d.empiricalBayesEstimate( aHat );
      else if( paceEstimator == ebEstimator )
  aTilde = d.subsetEstimate( aHat );
      else aTilde = d.nestedEstimate( aHat );
      break;
    case pace2Estimator:
    case pace4Estimator:
    case pace6Estimator:
      DoubleVector AHat = aHat.square();
      ChisqMixture dc = new ChisqMixture();
      dc.fit( AHat, MixtureDistribution.NNMMethod );
      DoubleVector ATilde;
      if( paceEstimator == pace6Estimator )
  ATilde = dc.pace6( AHat );
      else if( paceEstimator == pace2Estimator )
  ATilde = dc.pace2( AHat );
      else ATilde = dc.pace4( AHat );
      aTilde = ATilde.sqrt().times( aHat.sign() );
      break;
    case olsEstimator:
      aTilde = aHat.copy();
      break;
    case aicEstimator:
    case bicEstimator:
    case ricEstimator:
    case olscEstimator:
      if(paceEstimator == aicEstimator) olscThreshold = 2;
      else if(paceEstimator == bicEstimator) olscThreshold = Math.log( n );
      else if(paceEstimator == ricEstimator) olscThreshold = 2*Math.log( kr );
      aTilde = aHat.copy();
      for( int i = 0; i < aTilde.size(); i++ )
  if( Math.abs(aTilde.get(i)) < Math.sqrt(olscThreshold) )
    aTilde.set(i, 0);
    }
    PaceMatrix YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
    X.rsolve( YTilde, pvt, pvt.size() );
    DoubleVector betaTilde = YTilde.getColumn(0).unpivoting( pvt, kr );
   
    return betaTilde.getArrayCopy();
  }
View Full Code Here

  public static void main( String args[] )
  {
 
    double points[] = {2,1,2,3,3};
    double values[] = {3,2,4,1,3};
    DiscreteFunction d = new DiscreteFunction( new DoubleVector( points ),
                 new DoubleVector( values ));
    System.out.println( d );
    d.normalize();
    System.out.println( "d (after normalize) = \n" + d );
    points[1] = 10;
    System.out.println( "d (after setting [1]) = \n" + d);
View Full Code Here

  
   *  @param data the data supposedly generated from the mixture
   *  @return the set of fitting intervals
   */
  public PaceMatrix  fittingIntervals( DoubleVector data ) {
    DoubleVector left = data.cat( data.minus( fittingIntervalLength ) );
    DoubleVector right = data.plus( fittingIntervalLength ).cat( data );
 
    PaceMatrix a = new PaceMatrix(left.size(), 2);
 
    a.setMatrix(0, left.size()-1, 0, left);
    a.setMatrix(0, right.size()-1, 1, right);
 
    return a;
  }
View Full Code Here

   * @param x the value
   * @return the empirical Bayes estimate
   */
  public double  empiricalBayesEstimate ( double x ) {
    if( Math.abs(x) > 10 ) return x; // pratical consideration; modify later
    DoubleVector d =
    Maths.dnormLog( x, mixingDistribution.getPointValues(), 1 );
   
    d.minusEquals( d.max() );
    d = d.map("java.lang.Math", "exp");
    d.timesEquals( mixingDistribution.getFunctionValues() );
    return mixingDistribution.getPointValues().innerProduct( d ) / d.sum();
  }
View Full Code Here

   *
   * @param x the vector
   * @return the empirical Bayes estimate
   */
  public DoubleVector empiricalBayesEstimate( DoubleVector x ) {
    DoubleVector pred = new DoubleVector( x.size() );
    for(int i = 0; i < x.size(); i++ )
      pred.set(i, empiricalBayesEstimate(x.get(i)) );
    trim( pred );
    return pred;
  }
View Full Code Here

   * @param x the vector
   * @return the optimal nested model estimate
   */
  public DoubleVector  nestedEstimate( DoubleVector x ) {
   
    DoubleVector chf = new DoubleVector( x.size() );
    for(int i = 0; i < x.size(); i++ ) chf.set( i, hf( x.get(i) ) );
    chf.cumulateInPlace();
    int index = chf.indexOfMax();
    DoubleVector copy = x.copy();
    if( index < x.size()-1 ) copy.set( index + 1, x.size()-1, 0 );
    trim( copy );
    return copy;
  }
View Full Code Here

   * @param x the vector
   * @return the estimate of optimal subset selection
   */
  public DoubleVector  subsetEstimate( DoubleVector x ) {

    DoubleVector h = h( x );
    DoubleVector copy = x.copy();
    for( int i = 0; i < x.size(); i++ )
      if( h.get(i) <= 0 ) copy.set(i, 0);
    trim( copy );
    return copy;
  }
View Full Code Here

  
   *  @param x the value
   *  @return the value of h(x) / f(x)
   */
  public double hf( double x ) {
    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();

    DoubleVector d = Maths.dnormLog( x, points, 1 );
    d.minusEquals( d.max() );

    d = (DoubleVector) d.map("java.lang.Math", "exp");
    d.timesEquals( values )

    return ((DoubleVector) points.times(2*x).minusEquals(x*x))
    .innerProduct( d ) / d.sum();
  }
View Full Code Here

TOP

Related Classes of weka.core.matrix.DoubleVector

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.