Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.regression.base.AggregationUtils.java

Here you can find all the information about the file org.dgpf.gp.regression.base.AggregationUtils.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-07-24 15:54:19
 * Original Filename: org.dgpf.gp.regression.RegressionUtils.java
 * Version          : 1.0.0
 * Last modification: 2006-07-24
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.dgpf.gp.regression.base;

import org.dgpf.gp.regression.expressions.binary.AddHandler;
import org.dgpf.gp.regression.expressions.binary.DivHandler;
import org.dgpf.gp.regression.expressions.binary.MaxHandler;
import org.dgpf.gp.regression.expressions.binary.MinHandler;
import org.dgpf.gp.regression.expressions.binary.MulHandler;
import org.dgpf.gp.regression.expressions.binary.PowerHandler;
import org.dgpf.gp.regression.expressions.binary.SubHandler;
import org.dgpf.gp.regression.expressions.parameterless.ConstantHandler;
import org.dgpf.gp.regression.expressions.parameterless.VariableHandler;
import org.dgpf.gp.regression.expressions.unary.AbsHandler;
import org.dgpf.gp.regression.netimpl.FullyConnectedNetworkImpl;
import org.dgpf.search.api.utils.WeightedSetBuilder;
import org.sfc.math.Mathematics;
import org.sfc.math.stochastic.Randomizer;
import org.sfc.utils.Typesafe;

/**
 * The utils for symbolic regression.
 *
 * @author Thomas Weise
 */

public final class AggregationUtils
  {
/**
 * The default count of nodes.
 */

  public  static  final int   DEFAULT_NODE_COUNT            = 16;
/**
 * The default count of simulations.
 */

  public  static  final int   DEFAULT_SIMULATION_COUNT      =
                                    (AggregationContext.MAX_SIM*2);
/**
 * The default count of steps per simulation.
 */

  public  static  final long  DEFAULT_STEPS_PER_SIMULATION  =
                                        (DEFAULT_NODE_COUNT+5);
/**
 * The default network implementation factory.
 */

  public  static  final INetworkImplFactory DEFAULT_NETWORK_IMPL_FACTORY =
     FullyConnectedNetworkImpl.FACTORY;
    
/**
 * The default maximum count of variables available.
 * @see AggregationDefinition#get_max_variables()
 */

  public  static  final int DEFAULT_MAX_VARIABLES      = 6;
/**
 * The default maximum depth of a formula.
 * @see AggregationDefinition#get_max_depth()
 */

  public  static  final int DEFAULT_MAX_DEPTH          = 5;
  
/**
 * The maximum count of formulas allowed in one calculation.
 * @see AggregationDefinition#get_max_formulas()
 */

  public  static  final int DEFAULT_MAX_FORMULAS        = 5;
  
/**
 * The equ chars.
 */

          static  final char[]  EQU = " = ".toCharArray();
  

/**
 * The default expression set.
 */

  public static final ExpressionSet  DEFAULT_EXPRESSION_SET ;

  
  static
    {
    WeightedSetBuilder<IExpressionHandler> l_sb;
    
    l_sb = new WeightedSetBuilder<IExpressionHandler>(
                                        IExpressionHandler.class);
    
    l_sb.add(VariableHandler.INSTANCE,     2.0d);
    l_sb.add(ConstantHandler.INSTANCE,     0.3d);
    l_sb.add(AddHandler.INSTANCE,          1.0d);
    l_sb.add(SubHandler.INSTANCE,          1.0d);
    l_sb.add(MulHandler.INSTANCE,          1.0d);
    l_sb.add(DivHandler.INSTANCE,          0.7d);
    l_sb.add(MaxHandler.INSTANCE,          0.7d);
    l_sb.add(MinHandler.INSTANCE,          0.7d);
    l_sb.add(PowerHandler.INSTANCE,        0.3d);
    l_sb.add(AbsHandler.INSTANCE,          0.7d);
    
    DEFAULT_EXPRESSION_SET = new ExpressionSet(l_sb);
    }
        
/**
 * The default values for constants.
 */

  private static  final double[]  DEFAULT_CONSTANTS = new double[]
    {  0.0d, 0.5d, 1.0d, 2.0d, -1.0d,  Math.PI, Math.E, -0.5d, -2.0d,
       Mathematics.SQRT_2};
          
  
/**
 * The minimum std deviation for mutation purposes.
 */

  private static  final double  MIN_DEV = (
      (((Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE))    +
       ((Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE)))   +
      (((Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE))    +
       ((Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE)     +
        (Double.MIN_VALUE + Double.MIN_VALUE))) );
/**
 * Ya cannot do this.
 */

  private AggregationUtils()
    {
    Typesafe.do_not_call();
    }
  
/**
 * Obtain the name of the variable at the specified index.
 * @param p_id    The variable's id.
 * @param p_dest  The destination string builder.
 */

  public  static  final void  get_variable_name(      int           p_id,
                                                final StringBuilder p_dest)
    {
    do
      {
      p_dest.append( (char)('a' + (p_id % 26)) );
      p_id /= 26;
      } while(p_id != 0);
    }
  
/**
 * Create a new constant value.
 * @param p_r   The randomizer to be used.
 * @return  The new constant value.
 */

  public  static  final double  create_constant (final Randomizer p_r)
    {    
    double      l_d, l_d2;
    int         l_e;
    
    
    switch(p_r.nextInt(10))
      {      
      case 0:
        {
        l_d = 0.0d;
        for(l_e = p_r.nextInt(6); l_e >= 0; l_e--)
          {
          l_d = ((10.0d * l_d) + p_r.normal(0.0d, 10.0d));
          }
        return l_d;
        }
    
      case 1:
        {
        do
          {
          do
            {
            l_d = create_constant(p_r);
            } while(l_d == 0.0d);
          do
            {
            l_d2 = create_constant(p_r);
            } while(l_d2 == 0.0d);
          
          l_d2 = (l_d * l_d2);
          } while(!(Mathematics.is_number(l_d2)));
        return l_d2;
        }
    
      case 2:
        {        
        do
          {
          do
            {
            l_d = create_constant(p_r);
            } while(l_d == 0.0d);
          do
            {
            l_d2 = create_constant(p_r);
            } while(l_d2 == 0.0d);
          
          l_d2 = (l_d / l_d2);
          } while(!(Mathematics.is_number(l_d2)));
        return l_d2;
        }
    
      case 3:
        {        
        do
          {
          do
            {
            l_d = create_constant(p_r);
            } while(l_d < 0.0d);
          do
            {
            l_d2 = create_constant(p_r);
            } while(l_d2 == 0.0d);
          
          l_d2 = Math.pow(l_d, l_d2);
          } while(!(Mathematics.is_number(l_d2)));
        return l_d2;
        }
        
      default:
        {
        l_d = p_r.nextDouble();        
        return (DEFAULT_CONSTANTS[(int)(DEFAULT_CONSTANTS.length*l_d*l_d)]);
        }
      }
    }
  
/**
 * Mutate a constant value.
 * @param p_orig  The original value.
 * @param p_r     The randomizer to be used.
 * @return  The new constant value.
 */

  public  static  final double  mutate_constant (final double     p_orig,
                                                 final Randomizer p_r)
    { 
    double  l_d, l_e;
    
    
    do
      {
      switch(p_r.nextInt(100))
        {        
        case 0:
          {
          l_d = p_orig + create_constant(p_r);
          break;
          }
          
        case 1:
          {
          l_d = create_constant(p_r);
          break;
          }
        
        default:
          {
          l_e = Math.abs(p_orig);
    
          switch(p_r.nextInt(5))
            {
            case  0:  { l_e = Math.log(l_e + 1.0d); break; }
            case  1:  { l_e = Math.pow(l_e, 0.1d);  break; }
            case  2:  { l_e = (0.1d * l_e);         break; }
            case  3:  { l_e = 1.0d;                 break; }
            default:  { l_e = 1E-7;                 break; }  
            }
          
          l_d = p_r.normal(p_orig, Math.max(l_e, MIN_DEV));  
          }
        break;
        }      
      } while( l_d == p_orig );
    
    return l_d;
    }
  }

File Information:

file name:AggregationUtils.java
package:org.dgpf.gp.regression.base
qualified name:org.dgpf.gp.regression.base.AggregationUtils.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/regression/base/AggregationUtils.java
size:8.876 KB (9090 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-09-05 03:25:13 GMT+0000
last access: 2017-11-23 05:36:37 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-23 05:36:37 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo