public class SimbrainMath
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static umontreal.iro.lecuyer.rng.RandomStream |
DEFAULT_RANDOM_STREAM
A default random stream that can be used by any calls to SSJ
classes/functions.
|
static double |
log10of2 |
Constructor and Description |
---|
SimbrainMath() |
Modifier and Type | Method and Description |
---|---|
static void |
addNoise(double[] vector,
double noiselevel)
Add noise to a vector.
|
static double[] |
addVector(double[] base,
double[] add)
Add these vectors.
|
static java.awt.geom.Point2D |
cubicBezierMidpoint(java.awt.geom.Point2D src,
java.awt.geom.Point2D ctrl1,
java.awt.geom.Point2D ctrl2,
java.awt.geom.Point2D tar)
Returns the midpoint for a cubic Bezier curve.
|
static double |
determinant2by2(java.awt.geom.Point2D v0,
java.awt.geom.Point2D v1)
A fast determinant utility to find the determinant of the 2 by 2 matrix
made up of the vectors (stored as 2D points) v0 and v1, i.e.
|
static double |
distance(double[] src,
double[] tar)
Returns the Euclidean distance between src and target vectors.
|
static int |
distance(java.awt.Point src,
java.awt.Point tar)
Calculates the Euclidean distance between two points.
|
static double |
exp_sum(double[] arr)
An exponential sum of an array.
|
static double |
getAverage(double[] vals)
Helper function for computing mean values of an array of doubles.
|
static long[] |
getMatrixRowCompression(double[][] wtMatrix)
Returns a row compressed representation of a weight matrix represented as
a 2D array of doubles.
|
static double |
getMaximum(double[] theVec)
Finds the largest value in a vector array.
|
static double |
getMaximum(java.lang.Number[] arr)
Returns the maximum value of an array of numbers.
|
static double |
getMeanSquaredError(double[] src,
double[] tar)
Returns the mean squared error between a source and target vector.
|
static double |
getMinimum(java.lang.Number[] arr)
Returns the minimum value of an array of numbers.
|
static double[] |
getNoisyVector(double[] vector,
double noiselevel)
Add noise to a vector and return the result.
|
static double |
getVectorNorm(double[] vector)
Returns the Euclidean norm of the supplied vector.
|
static java.awt.geom.Point2D |
intersectParam(java.awt.geom.Point2D u0,
java.awt.geom.Point2D v0,
java.awt.geom.Point2D u1,
java.awt.geom.Point2D v1)
Returns the intersection parameters for two line segments.
|
static double |
inverf(double p)
Calculates the inverse of the error function.
|
static double |
log2(double val) |
static void |
main(java.lang.String[] yarhg)
Test randPermuteWithExclusion.
|
static double[] |
max(double[] one,
double[] two)
Finds the longer of two arrays.
|
static int |
max(int one,
int two)
Return the greater of two integers.
|
static java.awt.geom.Point2D |
midpoint(java.awt.geom.Point2D pt1,
java.awt.geom.Point2D pt2) |
static double[] |
multVector(double[] theVec,
double val)
Finds the entry-wise product of a vector and scalar.
|
static double[] |
normalizeVec(double[] vec)
A normalized version of the vector, i.e.
|
static void |
printVector(double[] da)
Prints out the vector list.
|
static double[] |
randomVector(int length)
Create a random vector with i components.
|
static double[] |
randomVector(int length,
double min,
double max)
Returns a vector of random values between min and max.
|
static int[] |
randPermute(int floor,
int ceil)
Returns a random permutation of all the integers between floor
(inclusive) and ceil (exclusive).
|
static int[] |
randPermuteWithExclusion(int floor,
int ceil,
int excluded)
Returns a random permutation of all the integers between floor
(inclusive) and ceil (exclusive) with the exception of one number
(excluded) which is intentionally excluded.
|
static double |
roundDouble(double d,
int places)
Round a double value to a specified number of places.
|
static double[] |
softMax(double[] vec)
The soft-max of the vector.
|
static double |
sum(double[] arr)
Sums all the values in an array.
|
public static final umontreal.iro.lecuyer.rng.RandomStream DEFAULT_RANDOM_STREAM
public static final double log10of2
public static double log2(double val)
public static int distance(java.awt.Point src, java.awt.Point tar)
src
- source pointtar
- target pointpublic static int[] randPermute(int floor, int ceil)
floor
- ceil
- public static int[] randPermuteWithExclusion(int floor, int ceil, int excluded)
floor
- ceil
- excluded
- public static double[] multVector(double[] theVec, double val)
theVec
- the vectorval
- the scalarpublic static int max(int one, int two)
one
- first inttwo
- second intpublic static double[] max(double[] one, double[] two)
one
- First arraytwo
- Second arraypublic static double sum(double[] arr)
arr
- the array to sumpublic static double exp_sum(double[] arr)
arr
- the array to exponential sumpublic static double[] normalizeVec(double[] vec)
vec
- the vector to normalizepublic static double[] softMax(double[] vec)
vec
- the vector to soft-maxpublic static double[] addVector(double[] base, double[] add)
base
- Base numberadd
- Number to be added to base numberpublic static double getAverage(double[] vals)
vals
- an array of valuespublic static void printVector(double[] da)
da
- Vector listpublic static java.awt.geom.Point2D midpoint(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2)
pt1
- the first pointpt2
- the second pointpublic static java.awt.geom.Point2D cubicBezierMidpoint(java.awt.geom.Point2D src, java.awt.geom.Point2D ctrl1, java.awt.geom.Point2D ctrl2, java.awt.geom.Point2D tar)
src
- the start point of the curvectrl1
- the first Bezier control pointctrl2
- the second Bezier control pointtar
- the end or target point of the curvepublic static double determinant2by2(java.awt.geom.Point2D v0, java.awt.geom.Point2D v1)
v0
- the first vector, stored as a Point2D, making up the first
column of the matrix we are taking the determinant of.v1
- the second vector, stored as a Point2D, making up the second
column of the matrix we are taking the determinant of.public static java.awt.geom.Point2D intersectParam(java.awt.geom.Point2D u0, java.awt.geom.Point2D v0, java.awt.geom.Point2D u1, java.awt.geom.Point2D v1)
u0
- the start point of the first line segmentv0
- the end point of the first line segmentu1
- the start point of the second line segmentv1
- the end point of the second line segmentpublic static double inverf(double p)
p
- Parameter to find inverse of the errorpublic static double getMaximum(double[] theVec)
theVec
- Vector arraypublic static double getMaximum(java.lang.Number[] arr)
arr
- public static double getMinimum(java.lang.Number[] arr)
arr
- public static void addNoise(double[] vector, double noiselevel)
vector
- vector to which noise should be addednoiselevel
- Noise levelpublic static double[] getNoisyVector(double[] vector, double noiselevel)
vector
- vector to which noise should be addednoiselevel
- Noise levelpublic static double[] randomVector(int length)
length
- i number of components in this vector.public static double[] randomVector(int length, double min, double max)
length
- number of components in the vectormin
- minimum value for random valuesmax
- maximum value for random valuespublic static final double roundDouble(double d, int places)
d
- double value to roundplaces
- placed to round dopublic static double getVectorNorm(double[] vector)
vector
- vector to checkpublic static double distance(double[] src, double[] tar)
src
- source vector.tar
- target vectorpublic static double getMeanSquaredError(double[] src, double[] tar) throws java.lang.IllegalArgumentException
src
- source vectortar
- target vectorjava.lang.IllegalArgumentException
- if src and tar have different lengthspublic static long[] getMatrixRowCompression(double[][] wtMatrix)
wtMatrix
- public static void main(java.lang.String[] yarhg)
yarhg
-