// Path: src/main/java/com/asher_stern/crf/function/DerivableFunction.java
// public abstract class DerivableFunction extends Function
// {
// 	/**
// 	 * Returns the gradient of the function in the given point.
// 	 * For example, if the function is f(x_1,x_2) = (x_1)^2 + x_1*x_2, then for [3,5] the returned gradient is [11 , 3].
// 	 * @param point the point is "x", the input for the function, for which the user needs the gradient.
// 	 * @return the gradient of the function in the given point.
// 	 */
// 	public abstract BigDecimal[] gradient(BigDecimal[] point);
// }
// 
// Path: src/main/java/com/asher_stern/crf/function/Function.java
// public abstract class Function
// {
// 	/**
// 	 * Returns the f(x) -- the value of the function in the given x.
// 	 * @param point the "point" is x -- the input for the function.
// 	 * @return the value of f(x)
// 	 */
// 	public abstract BigDecimal value(BigDecimal[] point);
// 	
// 	/**
// 	 * The size (dimension) of the input vector (x).
// 	 * @return the size (dimension) of the input vector (x).
// 	 */
// 	public abstract int size();
// }
// 
// Path: src/main/java/com/asher_stern/crf/function/TwiceDerivableFunction.java
// public abstract class TwiceDerivableFunction extends DerivableFunction
// {
// 	/**
// 	 * Returns the Hessian matrix for the given function in the given point (point is "x" -- the function input).
// 	 * @param point "point" is "x" -- the input for the function.
// 	 * @return the Hessian matrix -- the matrix of partial second derivations.
// 	 */
// 	public abstract BigDecimal[][] hessian(BigDecimal[] point);
// }
// 
// Path: src/main/java/com/asher_stern/crf/utilities/CrfException.java
// public class CrfException extends RuntimeException
// {
// 	private static final long serialVersionUID = 5414394233000815286L;
// 
// 	public CrfException()
// 	{
// 		super();
// 	}
// 
// 	public CrfException(String message, Throwable cause,
// 			boolean enableSuppression, boolean writableStackTrace)
// 	{
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public CrfException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// 	public CrfException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public CrfException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 	
// 
// }


import java.math.BigDecimal;
import com.asher_stern.crf.function.DerivableFunction;
import com.asher_stern.crf.function.Function;
import com.asher_stern.crf.function.TwiceDerivableFunction;
import com.asher_stern.crf.utilities.CrfException;
package com.asher_stern.crf.function.optimization;



/**
 * Represent "-f(x)" for a given function "f(x)".
 * <BR>
 * This negated function can be used when maximization of a function is needed, but a minimization algorithm is available.
 * Just minimize "-f(x)", and the resulting "x" is the point of the maximum for "f(x)".
 * 
 * @author Asher Stern
 * Date: Nov 6, 2014
 *
 */
public class NegatedFunction extends TwiceDerivableFunction
{
	public static NegatedFunction fromFunction(Function function)
	{
		return new NegatedFunction(function, null, null);
	}
	
	public static NegatedFunction fromDerivableFunction(DerivableFunction derivableFunction)
	{
		return new NegatedFunction(null,derivableFunction,null);
	}
	
// Path: src/main/java/com/asher_stern/crf/function/DerivableFunction.java
// public abstract class DerivableFunction extends Function
// {
// 	/**
// 	 * Returns the gradient of the function in the given point.
// 	 * For example, if the function is f(x_1,x_2) = (x_1)^2 + x_1*x_2, then for [3,5] the returned gradient is [11 , 3].
// 	 * @param point the point is "x", the input for the function, for which the user needs the gradient.
// 	 * @return the gradient of the function in the given point.
// 	 */
// 	public abstract BigDecimal[] gradient(BigDecimal[] point);
// }
// 
// Path: src/main/java/com/asher_stern/crf/function/Function.java
// public abstract class Function
// {
// 	/**
// 	 * Returns the f(x) -- the value of the function in the given x.
// 	 * @param point the "point" is x -- the input for the function.
// 	 * @return the value of f(x)
// 	 */
// 	public abstract BigDecimal value(BigDecimal[] point);
// 	
// 	/**
// 	 * The size (dimension) of the input vector (x).
// 	 * @return the size (dimension) of the input vector (x).
// 	 */
// 	public abstract int size();
// }
// 
// Path: src/main/java/com/asher_stern/crf/function/TwiceDerivableFunction.java
// public abstract class TwiceDerivableFunction extends DerivableFunction
// {
// 	/**
// 	 * Returns the Hessian matrix for the given function in the given point (point is "x" -- the function input).
// 	 * @param point "point" is "x" -- the input for the function.
// 	 * @return the Hessian matrix -- the matrix of partial second derivations.
// 	 */
// 	public abstract BigDecimal[][] hessian(BigDecimal[] point);
// }
// 
// Path: src/main/java/com/asher_stern/crf/utilities/CrfException.java
// public class CrfException extends RuntimeException
// {
// 	private static final long serialVersionUID = 5414394233000815286L;
// 
// 	public CrfException()
// 	{
// 		super();
// 	}
// 
// 	public CrfException(String message, Throwable cause,
// 			boolean enableSuppression, boolean writableStackTrace)
// 	{
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public CrfException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// 	public CrfException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public CrfException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 	
// 
// }


// Path: src/main/java/com/asher_stern/crf/function/optimization/NegatedFunction.java
import java.math.BigDecimal;
import com.asher_stern.crf.function.DerivableFunction;
import com.asher_stern.crf.function.Function;
import com.asher_stern.crf.function.TwiceDerivableFunction;
import com.asher_stern.crf.utilities.CrfException;

package com.asher_stern.crf.function.optimization;



/**
 * Represent "-f(x)" for a given function "f(x)".
 * <BR>
 * This negated function can be used when maximization of a function is needed, but a minimization algorithm is available.
 * Just minimize "-f(x)", and the resulting "x" is the point of the maximum for "f(x)".
 * 
 * @author Asher Stern
 * Date: Nov 6, 2014
 *
 */
public class NegatedFunction extends TwiceDerivableFunction
{
	public static NegatedFunction fromFunction(Function function)
	{
		return new NegatedFunction(function, null, null);
	}
	
	public static NegatedFunction fromDerivableFunction(DerivableFunction derivableFunction)
	{
		return new NegatedFunction(null,derivableFunction,null);
	}
	
	public static NegatedFunction fromTwiceDerivableFunction(TwiceDerivableFunction twiceDerivableFunction)