Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#NO_CONVERGENCE_WITH_ANY_START_POINT

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#NO_CONVERGENCE_WITH_ANY_START_POINT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cardumen_0052_s.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                             final double min, final double max,
                                             final double startValue)
    throws FunctionEvaluationException {
    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
            final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
            optima[i] = optimizer.optimize(f, goal, FastMath.min(bound1, bound2), FastMath.max(bound1, bound2));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 2
Source File: Cardumen_0052_t.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                             final double min, final double max,
                                             final double startValue)
    throws FunctionEvaluationException {
    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
            final double bound2 = i == 0 ? max : min - (0.5 * (bound1 - max));
            optima[i] = optimizer.optimize(f, goal, FastMath.min(bound1, bound2), FastMath.max(bound1, bound2));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 3
Source File: Cardumen_00119_t.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                             final double min, final double max,
                                             final double startValue)
    throws FunctionEvaluationException {
    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
            final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
            optima[i] = optimizer.optimize(f, goal, org.apache.commons.math.util.FastMath.max(min, min), org.apache.commons.math.util.FastMath.max(bound1, bound2));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 4
Source File: Cardumen_00119_s.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                             final double min, final double max,
                                             final double startValue)
    throws FunctionEvaluationException {
    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
            final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
            optima[i] = optimizer.optimize(f, goal, FastMath.min(bound1, bound2), FastMath.max(bound1, bound2));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 5
Source File: Math_62_MultiStartUnivariateRealOptimizer_s.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                             final double min, final double max,
                                             final double startValue)
    throws FunctionEvaluationException {
    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
            final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
            optima[i] = optimizer.optimize(f, goal, FastMath.min(bound1, bound2), FastMath.max(bound1, bound2));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 6
Source File: Math_62_MultiStartUnivariateRealOptimizer_t.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                             final double min, final double max,
                                             final double startValue)
    throws FunctionEvaluationException {
    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double s = (i == 0) ? startValue : min + generator.nextDouble() * (max - min);
            optima[i] = optimizer.optimize(f, goal, min, max, s);
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 7
Source File: MultiStartUnivariateRealOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateRealPointValuePair optimize(final FUNC f,
                                             final GoalType goal,
                                             final double min, final double max)
    throws FunctionEvaluationException {

    optima = new UnivariateRealPointValuePair[starts];
    totalEvaluations = 0;

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {
        try {
            final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
            final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
            optima[i] = optimizer.optimize(f, goal,
                                           FastMath.min(bound1, bound2),
                                           FastMath.max(bound1, bound2));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException ce) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the point with the best objective function value.
    return optima[0];
}
 
Example 8
Source File: BaseMultiStartMultivariateRealOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param f Function to optimize.
 * @param goal Goal type ({@link GoalType#MINIMIZE} or
 * {@link GoalType#MAXIMIZE}).
 * @param startPoint Start point.
 */
public RealPointValuePair optimize(final FUNC f,
                                   final GoalType goal,
                                   double[] startPoint)
    throws FunctionEvaluationException {
    optima = new RealPointValuePair[starts];

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {

        try {
            optima[i] = optimizer.optimize(f, goal,
                                           (i == 0 ? startPoint :
                                            generator.nextVector()));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException oe) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(goal);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the found point given the best objective function value.
    return optima[0];
}
 
Example 9
Source File: BaseMultiStartMultivariateVectorialOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public VectorialPointValuePair optimize(final FUNC f,
                                        double[] target, double[] weights,
                                        double[] startPoint)
    throws FunctionEvaluationException {

    optima = new VectorialPointValuePair[starts];

    // Multi-start loop.
    for (int i = 0; i < starts; ++i) {

        try {
            optima[i] = optimizer.optimize(f, target, weights,
                                           (i == 0 ? startPoint :
                                            generator.nextVector()));
        } catch (FunctionEvaluationException fee) {
            optima[i] = null;
        } catch (ConvergenceException oe) {
            optima[i] = null;
        }

        final int usedEvaluations = optimizer.getEvaluations();
        optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
        totalEvaluations += usedEvaluations;
    }

    sortPairs(target, weights);

    if (optima[0] == null) {
        throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                       starts);
    }

    // Return the found point given the best objective function value.
    return optima[0];
}
 
Example 10
Source File: 1_MultiStartUnivariateRealOptimizer.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
    public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
                                                 final double min, final double max,
                                                 final double startValue)
        throws FunctionEvaluationException {
        optima = new UnivariateRealPointValuePair[starts];
        totalEvaluations = 0;

        // Multi-start loop.
        for (int i = 0; i < starts; ++i) {
            try {
// start of generated patch
 final double bound1=min;
 final double bound2=min*(FastMath.abs(min)+FastMath.abs(bound1));
optima[i]=optimizer.optimize(f,goal,FastMath.min(bound1,bound2),FastMath.max(bound1,bound2));
// end of generated patch
/* start of original code
                final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max - min);
                final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max - min);
                optima[i] = optimizer.optimize(f, goal, FastMath.min(bound1, bound2), FastMath.max(bound1, bound2));
 end of original code*/
            } catch (FunctionEvaluationException fee) {
                optima[i] = null;
            } catch (ConvergenceException ce) {
                optima[i] = null;
            }

            final int usedEvaluations = optimizer.getEvaluations();
            optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
            totalEvaluations += usedEvaluations;
        }

        sortPairs(goal);

        if (optima[0] == null) {
            throw new ConvergenceException(LocalizedFormats.NO_CONVERGENCE_WITH_ANY_START_POINT,
                                           starts);
        }

        // Return the point with the best objective function value.
        return optima[0];
    }