List of usage examples for org.apache.commons.math3.optim MaxEval MaxEval
public MaxEval(int max)
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runPowell(BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { PowellOptimizer optimizer = new PowellOptimizer(1.e-6, 1.e-14); return optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint)); }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runSimplex(BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { // Rely on relative difference to test convergence, // to allow for vast differences in absolute error scale // between objective functions. ConvergenceChecker<PointValuePair> convergenceChecker = new SimpleValueChecker(1.e-6, 1.e-14); SimplexOptimizer optimizer = new SimplexOptimizer(convergenceChecker); MultiDirectionalSimplex simplex = new MultiDirectionalSimplex(objective.getSimplexStepSize()); return optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), simplex);/* ww w . j a v a 2 s . co m*/ }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runCmaes(BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { // Rely on relative difference to test convergence, // to allow for vast differences in absolute error scale // between objective functions. ConvergenceChecker<PointValuePair> convergenceChecker = new SimpleValueChecker(1.e-6, 1.e-14); MultivariateOptimizer optimizer = new CMAESOptimizer(objective.getMaxEvaluations(), 0.0001 * initialNorm, true, 0, 0, new MersenneTwister(), false, convergenceChecker); return optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds()), new CMAESOptimizer.PopulationSize(objective.getNrInterpolations()), new CMAESOptimizer.Sigma(objective.getStdDev())); }
From source file:eu.europeana.querylog.learn.Evaluate.java
/** * Performs the CMA learning algorithm./* ww w . j a v a 2s. c om*/ */ public String learningToRankWithCMAES() { startTime = System.currentTimeMillis(); pool = Executors.newFixedThreadPool(properties.getInt("bm25f.learn.concurrency")); try { final int dim = bm25fParams.length; int lambda = 4 + (int) (3. * Math.log(dim)); int maxEvaluations = 1800; double[] inSigma = floatArrayToDouble(getParamsVector(0.5f, 0.5f, 0.25f)); CMAESOptimizer optim = new CMAESOptimizer(maxEvaluations / 10, 1.0, false, 0, 10, new MersenneTwister(), true, new ConvergenceChecker<PointValuePair>() { @Override public boolean converged(int iteration, PointValuePair previous, PointValuePair pv) { maxValue = new Point(doubleArrayToFloat(pv.getFirst()), pv.getSecond().floatValue()); writeLogFile(); logger.info("{}", maxValue); return false; } }); PointValuePair pv = optim.optimize(new MaxEval(maxEvaluations), new ObjectiveFunction(new MultivariateFunction() { @Override public double value(double[] point) { return evaluateAssessments(doubleArrayToFloat(point)); } }), GoalType.MAXIMIZE, new SimpleBounds(floatArrayToDouble(minValues), floatArrayToDouble(maxValues)), new InitialGuess(floatArrayToDouble(bm25fParams)), new CMAESOptimizer.Sigma(inSigma), new CMAESOptimizer.PopulationSize(lambda)); maxValue = new Point(doubleArrayToFloat(pv.getFirst()), pv.getSecond().floatValue()); writeLogFile(); logger.info("final value: \n{}", maxValue); return paramsToXML(); } finally { pool.shutdown(); pool = null; } }
From source file:com.wwidesigner.modelling.PlayingRange.java
/** * Find fmin for a playing range, given fmax. * fmin is the highest frequency <= fmax that satisfies * either gain(fmin) == MinimumGain//from ww w. ja v a 2s . c om * or fmin is a local minimum of Im(Z)/Re(Z). * @param fmax - maximum frequency, as returned by findFmax(). */ public double findFmin(double fmax) { final double stepSize = fmax * Granularity; // Step size for search. // Upper bound on fmin is fmax. // findFmax ensures Im(Z(fmax)) == 0.0. double lowerFreq = fmax; Complex z_lo = calculator.calcZ(fmax, fingering); double g_lo = calculator.calcGain(lowerFreq, z_lo); double ratio = z_lo.getImaginary() / z_lo.getReal(); double minRatio = ratio + 1.0; if (g_lo < MinimumGain) { // Loop gain is too small, even at fmax. // There is no playing range here. throw new NoPlayingRange(fmax); } // Lower bound on fmin either has gain < MinimumGain // or is past a local minimum of Im(Z)/Re(Z). while (g_lo >= MinimumGain && ratio < minRatio) { minRatio = ratio; lowerFreq -= stepSize; if (lowerFreq < fmax / SearchBoundRatio) { throw new NoPlayingRange(fmax); } z_lo = calculator.calcZ(lowerFreq, fingering); g_lo = calculator.calcGain(lowerFreq, z_lo); ratio = z_lo.getImaginary() / z_lo.getReal(); } double freqGain; // Frequency at which gain == MinimumGain. double freqRatio; // Frequency of local minimum of Im(Z)/Re(Z). if (g_lo < MinimumGain) { // Find the point at which gain == MinimumGain. try { freqGain = solver.solve(50, gainOne, lowerFreq, fmax); } catch (Exception e) { System.out.println("Exception solving for fmin (gain): " + e.getMessage()); // e.printStackTrace(); throw new NoPlayingRange(fmax); } } else { freqGain = lowerFreq; } // Find the local minimum of Im(Z)/Re(Z). try { UnivariatePointValuePair minimum; minimum = optimizer.optimize(GoalType.MINIMIZE, new UnivariateObjectiveFunction(zRatio), new MaxEval(50), MaxIter.unlimited(), new SearchInterval(lowerFreq, fmax, 0.5 * (lowerFreq + fmax))); freqRatio = minimum.getPoint(); } catch (Exception e) { System.out.println("Exception solving for fmin (ratio): " + e.getMessage()); // e.printStackTrace(); throw new NoPlayingRange(fmax); } if (freqRatio > freqGain) { return freqRatio; } return freqGain; }
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runDirect(MultivariateOptimizer optimizer, BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { PointValuePair outcome;//from ww w .j a va2s . c o m // Run optimization first with the first-stage evaluator, if // specified EvaluatorInterface originalEvaluator = objective.getEvaluator(); if (objective.isRunTwoStageOptimization()) { objective.setEvaluator(objective.getFirstStageEvaluator()); } // Specify a target function value, to guard against // underconstrained // optimizations. Value here should be suitable for // CentsDeviationEvaluator, // and adequate for most other evaluators. outcome = optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(2 * objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), new DIRECTOptimizer.TargetFunctionValue(0.001), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds())); objective.setEvaluator(originalEvaluator); return outcome; }
From source file:com.itemanalysis.psychometrics.irt.equating.StockingLordMethodTest.java
/** * Item parameters and "true" linking coefficients are from example2 in Kolen's STUIRT program. * */// w ww. j av a2 s . c o m @Test public void stockingLordTestMixedFormatPARSCALE() { System.out.println("StockingLordMethod Test 4: STUIRT example 2 with PARSCALE parameters"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //Form X irmX.put("v1", new Irm3PL(0.751335, -0.897391, 0.244001, 1.7)); irmX.put("v2", new Irm3PL(0.955947, -0.811477, 0.242883, 1.7)); irmX.put("v3", new Irm3PL(0.497206, -0.858681, 0.260893, 1.7)); irmX.put("v4", new Irm3PL(0.724000, -0.123911, 0.243497, 1.7)); irmX.put("v5", new Irm3PL(0.865200, 0.205889, 0.319135, 1.7)); irmX.put("v6", new Irm3PL(0.658129, 0.555228, 0.277826, 1.7)); irmX.put("v7", new Irm3PL(1.082118, 0.950549, 0.157979, 1.7)); irmX.put("v8", new Irm3PL(0.988294, 1.377501, 0.084828, 1.7)); irmX.put("v9", new Irm3PL(1.248923, 1.614355, 0.181874, 1.7)); irmX.put("v10", new Irm3PL(1.116682, 2.353932, 0.246856, 1.7)); irmX.put("v11", new Irm3PL(0.438171, 3.217965, 0.309243, 1.7)); irmX.put("v12", new Irm3PL(1.082206, 4.441864, 0.192339, 1.7)); double[] step1 = { 1.097268, -1.097268 }; irmX.put("v13", new IrmGPCM2(0.269994, 0.003998, step1, 1.7)); double[] step2 = { 0.106514, -0.106514 }; irmX.put("v14", new IrmGPCM2(0.972506, 1.632662, step2, 1.7)); double[] step3 = { 2.102301, -2.102301 }; irmX.put("v15", new IrmGPCM2(0.378812, 3.464657, step3, 1.7)); double[] step4 = { -0.476513, 1.081282, -0.604770 }; irmX.put("v16", new IrmGPCM2(0.537706, 1.010053, step4, 1.7)); double[] step5 = { 1.007525, -0.197767, -0.809758 }; irmX.put("v17", new IrmGPCM2(0.554506, 2.432938, step5, 1.7)); //Form Y irmY.put("v1", new Irm3PL(0.887276, -1.334798, 0.134406, 1.7)); irmY.put("v2", new Irm3PL(1.184412, -1.129004, 0.237765, 1.7)); irmY.put("v3", new Irm3PL(0.609412, -1.464546, 0.151393, 1.7)); irmY.put("v4", new Irm3PL(0.923812, -0.576435, 0.240097, 1.7)); irmY.put("v5", new Irm3PL(0.822776, -0.476357, 0.192369, 1.7)); irmY.put("v6", new Irm3PL(0.707818, -0.235189, 0.189557, 1.7)); irmY.put("v7", new Irm3PL(1.306976, 0.242986, 0.165553, 1.7)); irmY.put("v8", new Irm3PL(1.295471, 0.598029, 0.090557, 1.7)); irmY.put("v9", new Irm3PL(1.366841, 0.923206, 0.172993, 1.7)); irmY.put("v10", new Irm3PL(1.389624, 1.380666, 0.238008, 1.7)); irmY.put("v11", new Irm3PL(0.293806, 2.028070, 0.203448, 1.7)); irmY.put("v12", new Irm3PL(0.885347, 3.152928, 0.195473, 1.7)); double[] step1Y = { 0.893232, -0.893232 }; irmY.put("v13", new IrmGPCM2(0.346324, -0.494115, step1Y, 1.7)); double[] step2Y = { 0.099750, -0.099750 }; irmY.put("v14", new IrmGPCM2(1.252012, 0.856264, step2Y, 1.7)); double[] step3Y = { 1.850498, -1.850498 }; irmY.put("v15", new IrmGPCM2(0.392282, 2.825801, step3Y, 1.7)); double[] step4Y = { -0.300428, 0.761846, -0.461417 }; irmY.put("v16", new IrmGPCM2(0.660841, 0.342977, step4Y, 1.7)); double[] step5Y = { 1.001974, -0.107221, -0.894753 }; irmY.put("v17", new IrmGPCM2(0.669612, 1.643267, step5Y, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); StockingLordMethod sl = new StockingLordMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); sl.setPrecision(6); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(sl), GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] slCoefficients = optimum.getPoint(); sl.setIntercept(slCoefficients[0]); sl.setScale(slCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + slCoefficients[0] + " A = " + slCoefficients[1]); assertEquals(" Intercept test", -0.456487, sl.getIntercept(), 1e-6); assertEquals(" Scale test", 0.815445, sl.getScale(), 1e-6); System.out.println(); }
From source file:com.itemanalysis.psychometrics.irt.equating.HaebaraMethodTest.java
@Test public void haebaraMethodTestMixedFormat2() { System.out.println("HaebaraMethod Test 4: Mixed format test, symmetric, PARSCALE parameters"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //Form X//ww w . j a va 2 s . c o m irmX.put("v1", new Irm3PL(0.751335, -0.897391, 0.244001, 1.7)); irmX.put("v2", new Irm3PL(0.955947, -0.811477, 0.242883, 1.7)); irmX.put("v3", new Irm3PL(0.497206, -0.858681, 0.260893, 1.7)); irmX.put("v4", new Irm3PL(0.724000, -0.123911, 0.243497, 1.7)); irmX.put("v5", new Irm3PL(0.865200, 0.205889, 0.319135, 1.7)); irmX.put("v6", new Irm3PL(0.658129, 0.555228, 0.277826, 1.7)); irmX.put("v7", new Irm3PL(1.082118, 0.950549, 0.157979, 1.7)); irmX.put("v8", new Irm3PL(0.988294, 1.377501, 0.084828, 1.7)); irmX.put("v9", new Irm3PL(1.248923, 1.614355, 0.181874, 1.7)); irmX.put("v10", new Irm3PL(1.116682, 2.353932, 0.246856, 1.7)); irmX.put("v11", new Irm3PL(0.438171, 3.217965, 0.309243, 1.7)); irmX.put("v12", new Irm3PL(1.082206, 4.441864, 0.192339, 1.7)); double[] step1 = { 1.097268, -1.097268 }; irmX.put("v13", new IrmGPCM2(0.269994, 0.003998, step1, 1.7)); double[] step2 = { 0.106514, -0.106514 }; irmX.put("v14", new IrmGPCM2(0.972506, 1.632662, step2, 1.7)); double[] step3 = { 2.102301, -2.102301 }; irmX.put("v15", new IrmGPCM2(0.378812, 3.464657, step3, 1.7)); double[] step4 = { -0.476513, 1.081282, -0.604770 }; irmX.put("v16", new IrmGPCM2(0.537706, 1.010053, step4, 1.7)); double[] step5 = { 1.007525, -0.197767, -0.809758 }; irmX.put("v17", new IrmGPCM2(0.554506, 2.432938, step5, 1.7)); //Form Y irmY.put("v1", new Irm3PL(0.887276, -1.334798, 0.134406, 1.7)); irmY.put("v2", new Irm3PL(1.184412, -1.129004, 0.237765, 1.7)); irmY.put("v3", new Irm3PL(0.609412, -1.464546, 0.151393, 1.7)); irmY.put("v4", new Irm3PL(0.923812, -0.576435, 0.240097, 1.7)); irmY.put("v5", new Irm3PL(0.822776, -0.476357, 0.192369, 1.7)); irmY.put("v6", new Irm3PL(0.707818, -0.235189, 0.189557, 1.7)); irmY.put("v7", new Irm3PL(1.306976, 0.242986, 0.165553, 1.7)); irmY.put("v8", new Irm3PL(1.295471, 0.598029, 0.090557, 1.7)); irmY.put("v9", new Irm3PL(1.366841, 0.923206, 0.172993, 1.7)); irmY.put("v10", new Irm3PL(1.389624, 1.380666, 0.238008, 1.7)); irmY.put("v11", new Irm3PL(0.293806, 2.028070, 0.203448, 1.7)); irmY.put("v12", new Irm3PL(0.885347, 3.152928, 0.195473, 1.7)); double[] step1Y = { 0.893232, -0.893232 }; irmY.put("v13", new IrmGPCM2(0.346324, -0.494115, step1Y, 1.7)); double[] step2Y = { 0.099750, -0.099750 }; irmY.put("v14", new IrmGPCM2(1.252012, 0.856264, step2Y, 1.7)); double[] step3Y = { 1.850498, -1.850498 }; irmY.put("v15", new IrmGPCM2(0.392282, 2.825801, step3Y, 1.7)); double[] step4Y = { -0.300428, 0.761846, -0.461417 }; irmY.put("v16", new IrmGPCM2(0.660841, 0.342977, step4Y, 1.7)); double[] step5Y = { 1.001974, -0.107221, -0.894753 }; irmY.put("v17", new IrmGPCM2(0.669612, 1.643267, step5Y, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); HaebaraMethod hb = new HaebaraMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); hb.setPrecision(4); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); org.apache.commons.math3.optim.PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(hb), org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] hbCoefficients = optimum.getPoint(); hb.setIntercept(hbCoefficients[0]); hb.setScale(hbCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + hbCoefficients[0] + " A = " + hbCoefficients[1]); assertEquals(" Intercept test", -0.446101, hb.getIntercept(), 1e-4); assertEquals(" Scale test", 0.805049, hb.getScale(), 1e-4); System.out.println(); }
From source file:edu.cmu.tetrad.sem.GeneralizedSemIm.java
public DataSet simulateDataMinimizeSurface(int sampleSize, boolean latentDataSaved) { final Map<String, Double> variableValues = new HashMap<String, Double>(); final double func_tolerance = 1.0e-4; final double param_tolerance = 1.0e-3; List<Node> continuousVariables = new LinkedList<Node>(); final List<Node> variableNodes = pm.getVariableNodes(); // Work with a copy of the variables, because their type can be set externally. for (Node node : variableNodes) { ContinuousVariable var = new ContinuousVariable(node.getName()); var.setNodeType(node.getNodeType()); if (var.getNodeType() != NodeType.ERROR) { continuousVariables.add(var); }/*from w w w . j ava 2 s . c o m*/ } DataSet fullDataSet = new ColtDataSet(sampleSize, continuousVariables); final Context context = new Context() { public Double getValue(String term) { Double value = parameterValues.get(term); if (value != null) { return value; } value = variableValues.get(term); if (value != null) { return value; } throw new IllegalArgumentException("No value recorded for '" + term + "'"); } }; final double[] _metric = new double[1]; MultivariateFunction function = new MultivariateFunction() { double metric; public double value(double[] doubles) { for (int i = 0; i < variableNodes.size(); i++) { variableValues.put(variableNodes.get(i).getName(), doubles[i]); } double[] image = new double[doubles.length]; for (int i = 0; i < variableNodes.size(); i++) { Node node = variableNodes.get(i); Expression expression = pm.getNodeExpression(node); image[i] = expression.evaluate(context); if (Double.isNaN(image[i])) { throw new IllegalArgumentException("Undefined value for expression " + expression); } } metric = 0.0; for (int i = 0; i < variableNodes.size(); i++) { double diff = doubles[i] - image[i]; metric += diff * diff; } for (int i = 0; i < variableNodes.size(); i++) { variableValues.put(variableNodes.get(i).getName(), image[i]); } _metric[0] = metric; return metric; } }; MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7); // Do the simulation. ROW: for (int row = 0; row < sampleSize; row++) { // Take random draws from error distributions. for (int i = 0; i < variableNodes.size(); i++) { Node variable = variableNodes.get(i); Node error = pm.getErrorNode(variable); Expression expression = pm.getNodeExpression(error); double value = expression.evaluate(context); if (Double.isNaN(value)) { throw new IllegalArgumentException("Undefined value for expression: " + expression); } variableValues.put(error.getName(), value); } for (int i = 0; i < variableNodes.size(); i++) { Node variable = variableNodes.get(i); variableValues.put(variable.getName(), 0.0);// RandomUtil.getInstance().nextUniform(-5, 5)); } while (true) { double[] values = new double[variableNodes.size()]; for (int i = 0; i < values.length; i++) { values[i] = variableValues.get(variableNodes.get(i).getName()); } PointValuePair pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function), GoalType.MINIMIZE, new MaxEval(100000)); values = pair.getPoint(); for (int i = 0; i < variableNodes.size(); i++) { if (isSimulatePositiveDataOnly() && values[i] < 0) { row--; continue ROW; } if (!Double.isNaN(selfLoopCoef) && row > 0) { values[i] += selfLoopCoef * fullDataSet.getDouble(row - 1, i); } variableValues.put(variableNodes.get(i).getName(), values[i]); fullDataSet.setDouble(row, i, values[i]); } if (_metric[0] < 0.01) { break; // while } } } if (latentDataSaved) { return fullDataSet; } else { return DataUtils.restrictToMeasured(fullDataSet); } }
From source file:com.itemanalysis.psychometrics.irt.equating.HaebaraMethodTest.java
@Test public void haebaraMethodTestMixedFormat3() { System.out.println("HaebaraMethod Test 5: Mixed format test, symmetric, Graded Response"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //3pl items//from w w w .j ava 2 s. c o m irmX.put("v1", new Irm3PL(1.0755, -1.8758, 0.1240, 1.7)); irmX.put("v2", new Irm3PL(0.6428, -0.9211, 0.1361, 1.7)); irmX.put("v3", new Irm3PL(0.6198, -1.3362, 0.1276, 1.7)); irmX.put("v4", new Irm3PL(0.6835, -1.8967, 0.1619, 1.7)); irmX.put("v5", new Irm3PL(0.9892, -0.6427, 0.2050, 1.7)); irmX.put("v6", new Irm3PL(0.5784, -0.8181, 0.1168, 1.7)); irmX.put("v7", new Irm3PL(0.9822, -0.9897, 0.1053, 1.7)); irmX.put("v8", new Irm3PL(1.6026, -1.2382, 0.1202, 1.7)); irmX.put("v9", new Irm3PL(0.8988, -0.5180, 0.1320, 1.7)); irmX.put("v10", new Irm3PL(1.2525, -0.7164, 0.1493, 1.7)); //gpcm items double[] step1 = { -2.1415, 0.0382, 0.6551 }; irmX.put("v11", new IrmGRM(1.1196, step1, 1.7)); double[] step2 = { -1.7523, -1.0660, 0.3533 }; irmX.put("v12", new IrmGRM(1.2290, step2, 1.7)); double[] step3 = { -2.3126, -1.8816, 0.7757 }; irmX.put("v13", new IrmGRM(0.6405, step3, 1.7)); double[] step4 = { -1.9728, -0.2810, 1.1387 }; irmX.put("v14", new IrmGRM(1.1622, step4, 1.7)); double[] step5 = { -2.2207, -0.8252, 0.9702 }; irmX.put("v15", new IrmGRM(1.2249, step5, 1.7)); //3pl items irmY.put("v1", new Irm3PL(0.7444, -1.5617, 0.1609, 1.7)); irmY.put("v2", new Irm3PL(0.5562, -0.1031, 0.1753, 1.7)); irmY.put("v3", new Irm3PL(0.5262, -1.0676, 0.1602, 1.7)); irmY.put("v4", new Irm3PL(0.6388, -1.3880, 0.1676, 1.7)); irmY.put("v5", new Irm3PL(0.8793, -0.2051, 0.1422, 1.7)); irmY.put("v6", new Irm3PL(0.4105, 0.0555, 0.2120, 1.7)); irmY.put("v7", new Irm3PL(0.7686, -0.3800, 0.2090, 1.7)); irmY.put("v8", new Irm3PL(1.0539, -0.7570, 0.1270, 1.7)); irmY.put("v9", new Irm3PL(0.7400, 0.0667, 0.1543, 1.7)); irmY.put("v10", new Irm3PL(0.7479, 0.0281, 0.1489, 1.7)); //gpcm items double[] step6 = { -1.7786, 0.7177, 1.45011 }; irmY.put("v11", new IrmGRM(0.9171, step6, 1.7)); double[] step7 = { -1.4115, -0.4946, 1.15969 }; irmY.put("v12", new IrmGRM(0.9751, step7, 1.7)); double[] step8 = { -1.8478, -1.4078, 1.51339 }; irmY.put("v13", new IrmGRM(0.5890, step8, 1.7)); double[] step9 = { -1.6151, 0.3002, 2.04728 }; irmY.put("v14", new IrmGRM(0.9804, step9, 1.7)); double[] step10 = { -1.9355, -0.2267, 1.88991 }; irmY.put("v15", new IrmGRM(1.0117, step10, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); HaebaraMethod hb = new HaebaraMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); hb.setPrecision(4); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); org.apache.commons.math3.optim.PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(hb), org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] hbCoefficients = optimum.getPoint(); hb.setIntercept(hbCoefficients[0]); hb.setScale(hbCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + hbCoefficients[0] + " A = " + hbCoefficients[1]); assertEquals(" Intercept test", 0.715912, hb.getIntercept(), 1e-4); assertEquals(" Scale test", 1.203554, hb.getScale(), 1e-4); System.out.println(); }