下面列出了java.lang.Math#sin ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Transformation rotaxis(double angle,Vector axis) {
// rotation about an axis
angle = angle*Math.PI/180;
axis=axis.normalize();
double a = axis.getX();
double b = axis.getY();
double c = axis.getZ();
double si = Math.sin(angle);
double co = Math.cos(angle);
Matrix rm = new Matrix(
(co+a*a*(1-co)),(-c*si+b*a*(1-co)),(b*si+c*a*(1-co)),
(c*si+a*b*(1-co)),(co+b*b*(1-co)),(-a*si+c*b*(1-co)),
(-b*si+a*c*(1-co)),(a*si+b*c*(1-co)),(co+c*c*(1-co)));
return new Transformation(rm.prod(matrix),vector);
}
public Object exp(Object param)
throws ParseException
{
if (param instanceof Complex)
{
Complex z = (Complex) param;
double x = z.re();
double y = z.im();
double mod = Math.exp(x);
return new Complex(mod*Math.cos(y),mod*Math.sin(y));
}
else if (param instanceof Number)
{
return new Double(Math.exp(((Number)param).doubleValue()));
}
throw new ParseException("Invalid parameter type");
}
public Transformation rotaxisz(double delta, double rho) {
// local rotation away from the local z-axis
// about an angle delta using an axis given by rho
// - used for splitting and random rotations
delta = delta*Math.PI/180;
rho = rho*Math.PI/180;
double a = Math.cos(rho);
double b = Math.sin(rho);
double si = Math.sin(delta);
double co = Math.cos(delta);
Matrix rm = new Matrix((co+a*a*(1-co)),(b*a*(1-co)),(b*si),
(a*b*(1-co)),(co+b*b*(1-co)),(-a*si),
(-b*si),(a*si),(co));
return new Transformation(matrix.prod(rm),vector);
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
private double ValorNormal(double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand();
u2 = Randomize.Rand();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt( -2 * Math.log(u1)) *
Math.sin(2 * Math.PI * u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
private double ValorNormal (double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand ();
u2 = Randomize.Rand ();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt (-2 * Math.log(u1)) * Math.sin (2*Math.PI*u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
private double ValorNormal (double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1=Randomize.Rand ();
u2=Randomize.Rand ();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt (-2 * Math.log(u1)) * Math.sin (2*Math.PI*u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
private double ValorNormal (double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1=Randomize.Rand ();
u2=Randomize.Rand ();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt (-2.0 * Math.log(u1)) * Math.sin (2.0*PI*u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
private double ValorNormal(double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand();
u2 = Randomize.Rand();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt( -2 * Math.log(u1)) * Math.sin(2 * PI * u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
public double ValorNormal(double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand();
u2 = Randomize.Rand();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt( -2.0 * Math.log(u1)) * Math.sin(2.0 * PI * u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
public double ValorNormal(double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand();
u2 = Randomize.Rand();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt( -2.0 * Math.log(u1)) * Math.sin(2.0 * Math.PI * u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
public double ValorNormal(double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand();
u2 = Randomize.Rand();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt( -2 * Math.log(u1)) * Math.sin(2 * PI * u2));
}
/** Generates a normal value with hope 0 and tipical deviation "desv */
private double ValorNormal(double desv) {
double u1, u2;
/* we generate 2 uniform values [0,1] */
u1 = Randomize.Rand();
u2 = Randomize.Rand();
/* we calcules a normal value with the uniform values */
return (desv * Math.sqrt( -2 * Math.log(u1)) * Math.sin(2 * PI * u2));
}
public Object sin(Object param)
throws ParseException
{
if (param instanceof Complex) {
return ((Complex)param).sin();
}
else if (param instanceof Number) {
return new Double(Math.sin(((Number)param).doubleValue()));
}
throw new ParseException("Invalid parameter type");
}
public Transformation rotz(double angle) {
// local rotation about z-axis
angle = angle*Math.PI/180;
Matrix rm = new Matrix(Math.cos(angle),-Math.sin(angle),0,
Math.sin(angle),Math.cos(angle),0,
0,0,1);
return new Transformation(matrix.prod(rm),vector);
}
float intensityFlickerPulse(int time) {
float i = (float)Math.sin((double)time * 0.05);
return i;
}
float intensityFlickerCompulse(int time) {
float i = (float)Math.sin((double)time*0.05) + (float)Math.sin((double)time*0.03);
return i;
}
private void Mutacion () {
int n_hijo, i, j, nq, n1, n2;
double z0, z1, x1, x2, si, co;
for (n_hijo=0; n_hijo<Landa; n_hijo++) {
/* Mutation of sigma */
if (n_sigma==1) /* if we use only a sigma, the sigma is adapted with Tau_1 */
Hijos[n_hijo].Gene[tabla.n_variables] *= ValorNormal (Tau_1);
else {
z0 = ValorNormal (Tau_0);
for (i=tabla.n_variables; i<tabla.n_variables + n_sigma; i++) {
z1 = ValorNormal (Tau);
Hijos[n_hijo].Gene[i] *= Math.exp (z1+z0);
/* The standard desviation is Epsilon_sigma if it becomes 0 */
if (Hijos[n_hijo].Gene[i]==0.0)
Hijos[n_hijo].Gene[i] = Epsilon_sigma;
}
}
/* Mutation of alfa */
for (i = tabla.n_variables + n_sigma; i<tabla.n_variables + n_sigma + n_alfa; i++) {
z0 = ValorNormal (Beta);
Hijos[n_hijo].Gene[i] += z0;
/* Si el valor mutado se sale del intervalo [-i,i], se proyecta
circularmente el valor a dicho intervalo */
if (Math.abs(Hijos[n_hijo].Gene[i])>i)
Hijos[n_hijo].Gene[i] -= 2 *i * signo (Hijos[n_hijo].Gene[i]);
}
/* Mutation of x */
/* we calculate the uncorrelated vector of mutations */
for (i=0; i<tabla.n_variables; i++)
if (tabla.n_variables + i < tabla.n_variables + n_sigma)
Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+i]);
else /* if there aren't more tipical desviations we use the latest */
Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+n_sigma-1]);
/* Correlation of the vector if we use the angles */
if (n_alfa!=0) {
nq = n_alfa;
for (j=nl_alfa; j<=nm_alfa; ++j) {
n1 = tabla.n_variables - j;
n2 = tabla.n_variables;
for (i=1; i<=j; ++i) {
x1 = Z[n1-1];
x2 = Z[n2-1];
si = Math.sin(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
co = Math.cos(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
Z[n2-1] = x1*si + x2*co;
Z[n1-1] = x1*co - x2*si;
--n2;
--nq;
}
}
}
/* Final mutation of X */
for (i=0; i<tabla.n_variables; i++) {
Hijos[n_hijo].Gene[i] += Z[i];
if (Hijos[n_hijo].Gene[i] < -(Math.PI/2.0))
Hijos[n_hijo].Gene[i] = -(Math.PI/2.0) + 1E-10;
if (Hijos[n_hijo].Gene[i] > (Math.PI/2.0))
Hijos[n_hijo].Gene[i] = (Math.PI/2.0) - 1E-10;
}
}
}
private void Mutacion () {
int n_hijo, i, j, nq, n1, n2;
double z0, z1, x1, x2, si, co;
for (n_hijo=0; n_hijo<Landa; n_hijo++) {
/* Mutation of sigma */
if (n_sigma==1) /* if we use only a sigma, the sigma is adapted with Tau_1 */
Hijos[n_hijo].Gene[tabla.n_variables] *= ValorNormal (Tau_1);
else {
z0 = ValorNormal (Tau_0);
for (i=tabla.n_variables; i < tabla.n_variables + n_sigma; i++) {
z1 = ValorNormal (Tau);
Hijos[n_hijo].Gene[i] *= Math.exp (z1+z0);
/* The standard desviation is Epsilon_sigma if it becomes 0 */
if (Hijos[n_hijo].Gene[i]==0.0)
Hijos[n_hijo].Gene[i] = Epsilon_sigma;
}
}
/* Mutation of alfa */
for (i = tabla.n_variables + n_sigma; i<tabla.n_variables + n_sigma + n_alfa; i++) {
z0 = ValorNormal (Beta);
Hijos[n_hijo].Gene[i] += z0;
/* Si el valor mutado se sale del intervalo [-i,i], se proyecta
circularmente el valor a dicho intervalo */
if (Math.abs(Hijos[n_hijo].Gene[i])>i) Hijos[n_hijo].Gene[i] -= 2.0 * PI * signo (Hijos[n_hijo].Gene[i]);
}
/* Mutation of x */
/* we calculate the uncorrelated vector of mutations */
for (i=0; i<tabla.n_variables; i++) {
if (tabla.n_variables + i < tabla.n_variables + n_sigma) Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+i]);
else Z[i] = ValorNormal (Hijos[n_hijo].Gene[tabla.n_variables+n_sigma-1]); /* if there aren't more tipical desviations we use the latest */
}
/* Correlation of the vector if we use the angles */
if (n_alfa!=0) {
nq = n_alfa;
for (j=nl_alfa; j<=nm_alfa; ++j) {
n1 = tabla.n_variables - j;
n2 = tabla.n_variables;
for (i=1; i<=j; ++i) {
x1 = Z[n1-1];
x2 = Z[n2-1];
si = Math.sin(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
co = Math.cos(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq - 1]);
Z[n2-1] = x1*si + x2*co;
Z[n1-1] = x1*co - x2*si;
--n2;
--nq;
}
}
}
/* Final mutation of X */
for (i=0; i<tabla.n_variables; i++) {
Hijos[n_hijo].Gene[i] += Z[i];
if (Hijos[n_hijo].Gene[i] < (-1.0 * (PI/2.0))) Hijos[n_hijo].Gene[i] = (-1.0 * (PI/2.0)) + 1E-10;
if (Hijos[n_hijo].Gene[i] > (PI/2.0)) Hijos[n_hijo].Gene[i] = (PI/2.0) - 1E-10;
}
}
}
private void Mutacion() {
int n_hijo, i, j, nq, n1, n2;
double z0, z1, x1, x2, si, co;
for (n_hijo = 0; n_hijo < Landa; n_hijo++) {
/* Mutation of sigma */
if (n_sigma == 1)
/* if we use only a sigma, the sigma is adapted with Tau_1 */
{
Hijos[n_hijo].Gene[tabla.n_variables] *= ValorNormal(Tau_1);
}
else {
z0 = ValorNormal(Tau_0);
for (i = tabla.n_variables; i < tabla.n_variables + n_sigma; i++) {
z1 = ValorNormal(Tau);
Hijos[n_hijo].Gene[i] *= Math.exp(z1 + z0);
/* The standard desviation is Epsilon_sigma if it becomes 0 */
if (Hijos[n_hijo].Gene[i] == 0.0) {
Hijos[n_hijo].Gene[i] = Epsilon_sigma;
}
}
}
/* Mutation of alfa */
for (i = tabla.n_variables + n_sigma;
i < tabla.n_variables + n_sigma + n_alfa; i++) {
z0 = ValorNormal(Beta);
Hijos[n_hijo].Gene[i] += z0;
/* Si el valor mutado se sale del intervalo [-i,i], se proyecta
circularmente el valor a dicho intervalo */
if (Math.abs(Hijos[n_hijo].Gene[i]) > i) {
Hijos[n_hijo].Gene[i] -= 2 * PI * signo(Hijos[n_hijo].Gene[i]);
}
}
/* Mutation of x */
/* we calculate the uncorrelated vector of mutations */
for (i = 0; i < tabla.n_variables; i++) {
if (tabla.n_variables + i < tabla.n_variables + n_sigma) {
Z[i] = ValorNormal(Hijos[n_hijo].Gene[tabla.n_variables + i]);
}
else
/* if there aren't more tipical desviations we use the latest */
{
Z[i] = ValorNormal(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma - 1]);
}
}
/* Correlation of the vector if we use the angles */
if (n_alfa != 0) {
nq = n_alfa;
for (j = nl_alfa; j <= nm_alfa; ++j) {
n1 = tabla.n_variables - j;
n2 = tabla.n_variables;
for (i = 1; i <= j; ++i) {
x1 = Z[n1 - 1];
x2 = Z[n2 - 1];
si = Math.sin(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq -
1]);
co = Math.cos(Hijos[n_hijo].Gene[tabla.n_variables + n_sigma + nq -
1]);
Z[n2 - 1] = x1 * si + x2 * co;
Z[n1 - 1] = x1 * co - x2 * si;
--n2;
--nq;
}
}
}
/* Final mutation of X */
for (i = 0; i < tabla.n_variables; i++) {
Hijos[n_hijo].Gene[i] += Z[i];
if (Hijos[n_hijo].Gene[i] < - (PI / 2.0)) {
Hijos[n_hijo].Gene[i] = - (PI / 2.0) + 1E-10;
}
if (Hijos[n_hijo].Gene[i] > (PI / 2.0)) {
Hijos[n_hijo].Gene[i] = (PI / 2.0) - 1E-10;
}
}
}
}
public static MR_double sin ( MR_double x ) { return new MR_double(Math.sin(x.get())); }