Package weka.core.matrix

Examples of weka.core.matrix.DoubleVector


  
   *  @param x the value
   *  @return the value of h(x)
   */
  public double h( double x ) {
    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();
    DoubleVector d = (DoubleVector) Maths.dnorm( x, points, 1 ).timesEquals( values )
    return ((DoubleVector) points.times(2*x).minusEquals(x*x))
    .innerProduct( d );
  }
View Full Code Here


  
   *  @param x the vector
   *  @return the value of h(x)
   */
  public DoubleVector h( DoubleVector x ) {
    DoubleVector h = new DoubleVector( x.size() );
    for( int i = 0; i < x.size(); i++ )
      h.set( i, h( x.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

  public static void  main(String args[]) {
    int n1 = 50;
    int n2 = 50;
    double mu1 = 0;
    double mu2 = 5;
    DoubleVector a = Maths.rnorm( n1, mu1, 1, new Random() );
    a = a.cat( Maths.rnorm( n2, mu2, 1, new Random() ) );
    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 unit variance normal\n" +
      "distributions. The example mixture used is of the form: \n\n" +
      "   0.5 * N(mu1, 1) + 0.5 * N(mu2, 1)\n" );

    System.out.println("It also tests three estimators: the subset\n" +
      "selector, the nested model selector, and the empirical Bayes\n" +
      "estimator. Quadratic losses of the estimators are given, \n" +
      "and are taken as the measure of their performance.");
    System.out.println("==========================================================");
    System.out.println( "mu1 = " + mu1 + " mu2 = " + mu2 +"\n" );

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

    System.out.println( "\nQuadratic loss of the raw data (i.e., the MLE) = " +
       a.sum2( means ) );
    System.out.println("==========================================================");

    // find the mixing distribution
    NormalMixture d = new NormalMixture();
    d.fit( a, NNMMethod );
    System.out.println( "The estimated mixing distribution is:\n" + d );
 
    DoubleVector pred = d.nestedEstimate( a.rev() ).rev();
    System.out.println( "\nThe Nested Estimate = \n" + pred );
    System.out.println( "Quadratic loss = " + pred.sum2( means ) );

    pred = d.subsetEstimate( a );
    System.out.println( "\nThe Subset Estimate = \n" + pred );
    System.out.println( "Quadratic loss = " + pred.sum2( means ) );

    pred = d.empiricalBayesEstimate( a );
    System.out.println( "\nThe Empirical Bayes Estimate = \n" + pred );
    System.out.println( "Quadratic loss = " + pred.sum2( means ) );
 
  }
View Full Code Here

   @param x the value
   *  @return true if the value can be considered
   */
  public boolean separable( DoubleVector data, int i0, int i1, double x ) {

    DoubleVector dataSqrt = data.sqrt();
    double xh = Math.sqrt( x );

    NormalMixture m = new NormalMixture();
    m.setSeparatingThreshold( separatingThreshold );
    return m.separable( dataSqrt, i0, i1, xh );
View Full Code Here

   *  earlier and not passed into here
   *  @return the set of support points
   */
  public DoubleVector  supportPoints( DoubleVector data, int ne ) {

    DoubleVector sp = new DoubleVector();
    sp.setCapacity( data.size() + 1 );

    if( data.get(0) < supportThreshold || ne != 0 )
      sp.addElement( 0 );
    for( int i = 0; i < data.size(); i++ )
      if( data.get( i ) > supportThreshold )
  sp.addElement( data.get(i) );
 
    // The following will be fixed later???
    if( sp.size() > maxNumSupportPoints )
      throw new IllegalArgumentException( "Too many support points. " );

    return sp;
  }
View Full Code Here

   @return the set of fitting intervals
   */
  public PaceMatrix  fittingIntervals( DoubleVector data ) {

    PaceMatrix a = new PaceMatrix( data.size() * 2, 2 );
    DoubleVector v = data.sqrt();
    int count = 0;
    double left, right;
    for( int i = 0; i < data.size(); i++ ) {
      left = v.get(i) - fittingIntervalLength;
      if( left < fittingIntervalThreshold ) left = 0;
      left = left * left;
      right = data.get(i);
      if( right < fittingIntervalThreshold )
  right = fittingIntervalThreshold;
      a.set( count, 0, left );
      a.set( count, 1, right );
      count++;
    }
    for( int i = 0; i < data.size(); i++ ) {
      left = data.get(i);
      if( left < fittingIntervalThreshold ) left = 0;
      right = v.get(i) + fittingIntervalThreshold;
      right = right * right;
      a.set( count, 0, left );
      a.set( count, 1, right );
      count++;
    }
View Full Code Here

   @return the pace6 estimate
   */
  public double  pace6 ( double x ) {
   
    if( x > 100 ) return x; // pratical consideration. will modify later
    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();
    DoubleVector mean = points.sqrt();
 
    DoubleVector d = Maths.dchisqLog( x, points );
    d.minusEquals( d.max() );
    d = d.map("java.lang.Math", "exp").timesEquals( values );
    double atilde = mean.innerProduct( d ) / d.sum();
    return atilde * atilde;
  }
View Full Code Here

   @param x the vector
   *  @return the pace6 estimate
   */
  public DoubleVector pace6( DoubleVector x ) {

    DoubleVector pred = new DoubleVector( x.size() );
    for(int i = 0; i < x.size(); i++ )
      pred.set(i, pace6(x.get(i)) );
    trim( pred );
    return pred;
  }
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.