Package weka.core.matrix

Examples of weka.core.matrix.DoubleVector


   @param x the vector
   *  @return the pace2 estimate
   */
  public DoubleVector  pace2( 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 pace4 estimate
   */
  public DoubleVector  pace4( 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 AHat the value
   *  @return the value of h(x) / f(x)
   */
  public double hf( double AHat ) {
   
    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();

    double x = Math.sqrt( AHat );
    DoubleVector mean = points.sqrt();
    DoubleVector d1 = Maths.dnormLog( x, mean, 1 );
    double d1max = d1.max();
    d1.minusEquals( d1max );
    DoubleVector d2 = Maths.dnormLog( -x, mean, 1 );
    d2.minusEquals( d1max );

    d1 = d1.map("java.lang.Math", "exp");
    d1.timesEquals( values )
    d2 = d2.map("java.lang.Math", "exp");
    d2.timesEquals( values )

    return ( ( points.minus(x/2)).innerProduct( d1 ) -
       ( points.plus(x/2)).innerProduct( d2 ) )
    / (d1.sum() + d2.sum());
  }
View Full Code Here

   @return the value of h(x)
   */
  public double h( double AHat ) {
   
    if( AHat == 0.0 ) return 0.0;
    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();
 
    double aHat = Math.sqrt( AHat );
    DoubleVector aStar = points.sqrt();
    DoubleVector d1 = Maths.dnorm( aHat, aStar, 1 ).timesEquals( values );
    DoubleVector d2 = Maths.dnorm( -aHat, aStar, 1 ).timesEquals( values );

    return points.minus(aHat/2).innerProduct( d1 ) -
           points.plus(aHat/2).innerProduct( d2 );
  }
View Full Code Here

   @param AHat the vector
   *  @return the value of h(x)
   */
  public DoubleVector h( DoubleVector AHat ) {
   
    DoubleVector h = new DoubleVector( AHat.size() );
    for( int i = 0; i < AHat.size(); i++ )
      h.set( i, h( AHat.get(i) ) );
    return h;
  }
View Full Code Here

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

    return Maths.dchisq(x, points).timesEquals(values).sum()
  }
View Full Code Here

   @param x the vector
   *  @return the value of f(x)
   */
  public DoubleVector f( DoubleVector x ) {
   
    DoubleVector f = new DoubleVector( x.size() );
    for( int i = 0; i < x.size(); i++ )
      f.set( i, h( f.get(i) ) );
    return f;
  }
View Full Code Here

    int n2 = 50;
    double ncp1 = 0;
    double ncp2 = 10;
    double mu1 = Math.sqrt( ncp1 );
    double mu2 = Math.sqrt( ncp2 );
    DoubleVector a = Maths.rnorm( n1, mu1, 1, new Random() );
    a = a.cat( Maths.rnorm(n2, mu2, 1, new Random()) );
    DoubleVector aNormal = a;
    a = a.square();
    a.sort();
 
    DoubleVector means = (new DoubleVector( n1, mu1 )).cat(new DoubleVector(n2, mu2));
 
    System.out.println("==========================================================");
    System.out.println("This is to test the estimation of the mixing\n" +
           "distribution of the mixture of non-central Chi-square\n" +
           "distributions. The example mixture used is of the form: \n\n" +
           "   0.5 * Chi^2_1(ncp1) + 0.5 * Chi^2_1(ncp2)\n" );

    System.out.println("It also tests the PACE estimators. Quadratic losses of the\n" +
           "estimators are given, measuring their performance.");
    System.out.println("==========================================================");
    System.out.println( "ncp1 = " + ncp1 + " ncp2 = " + ncp2 +"\n" );

    System.out.println( a.size() + " observations are: \n\n" + a );

    System.out.println( "\nQuadratic loss of the raw data (i.e., the MLE) = " +
      aNormal.sum2( means ) );
    System.out.println("==========================================================");
 
    // find the mixing distribution
    ChisqMixture d = new ChisqMixture();
    d.fit( a, NNMMethod );
    System.out.println( "The estimated mixing distribution is\n" + d )
 
    DoubleVector pred = d.pace2( a.rev() ).rev();
    System.out.println( "\nThe PACE2 Estimate = \n" + pred );
    System.out.println( "Quadratic loss = " +
      pred.sqrt().times(aNormal.sign()).sum2( means ) );
   
    pred = d.pace4( a );
    System.out.println( "\nThe PACE4 Estimate = \n" + pred );
    System.out.println( "Quadratic loss = " +
      pred.sqrt().times(aNormal.sign()).sum2( means ) );

    pred = d.pace6( a );
    System.out.println( "\nThe PACE6 Estimate = \n" + pred );
    System.out.println( "Quadratic loss = " +
      pred.sqrt().times(aNormal.sign()).sum2( means ) );
  }
View Full Code Here

  /** Return a DoubleVector that stores a column of the matrix
   *  @param j the index of the column
   *  @return the column
   */
  public DoubleVector  getColumn( int j ) {
    DoubleVector v = new DoubleVector( m );
    double [] a = v.getArray();
    for(int i = 0; i < m; i++)
      a[i] = A[i][j];
    return v;
  }
View Full Code Here

   @param i1 the index of the last element of the column
   *  @param j  the index of the column
   *  @return the DoubleVector
   */
  public DoubleVector  getColumn( int i0, int i1, int j ) {
    DoubleVector v = new DoubleVector( i1-i0+1 );
    double [] a = v.getArray();
    int count = 0;
    for( int i = i0; i <= i1; i++ ) {
      a[count] = A[i][j];
      count++;
    }
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.