This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A Generic Min Heap Priority Queue for Unity that uses supplied float values for its ordering. | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PriorityQueue<T> where T : class{ | |
struct ValueItem { | |
public T item; | |
public float value; | |
public ValueItem(T i, float v) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* fast floating point exp function | |
* must initialize table with buildexptable before using | |
Based on | |
A Fast, Compact Approximation of the Exponential Function | |
Nicol N. Schraudolph 1999 | |
Adapted to single precision to improve speed and added adjustment table to improve accuracy. | |
Alrecenk 2014 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string header = ...; | |
Variant glb = Variant::parseJSON(header); | |
glb["meshes"][glb["nodes"][glb["scenes"][0]["nodes"][0]]["mesh"]].printFormatted(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scratch; | |
import java.util.*; | |
public class islands { | |
public static void main(String args[]){ | |
boolean map[][] = generateIslands(180, 50, new Random(287), 25, 15, .3); | |
System.out.println(drawMap(map)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//performs a least squares fit of a polynomial function of the given degree | |
//mapping each input[k] vector to each output[k] vector | |
//returns the coefficients in a matrix | |
public static double[][] fitpolynomial(double input[][], double output[][], int degree){ | |
double[][] X = new double[input.length][]; | |
//Run the input through the polynomialization and add the bias term | |
for (int k = 0; k < input.length; k++){ | |
X[k] = polynomial(input[k], degree); | |
} | |
int inputs = X[0].length ;//number of inputs after the polynomial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//splits this node if it should and returns whether it did | |
//data is assumed to be a set of presorted lists where data[k][j] is the jth element of data when sorted by axis[k] | |
public boolean split(int minpoints){ | |
//if already split or one class or not enough points remaining then don't split | |
if (branchnode || totalpositive == 0 || totalnegative == 0 || totalpositive + totalnegative < minpoints){ | |
return false; | |
}else{ | |
int bestaxis = -1, splitafter=-1; | |
double bestscore = Double.MAX_VALUE;//any valid split will beat no split | |
int bestLp=0, bestLn=0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//makes a vector of length one | |
public static void normalize(double a[]){ | |
double scale = 0 ; | |
for(int k=0;k<a.length;k++){ | |
scale+=a[k]*a[k]; | |
} | |
scale = 1/Math.sqrt(scale); | |
for(int k=0;k<a.length;k++){ | |
a[k]*=scale ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//bootstrap aggregating of training data for a random forest | |
Random rand = new Random(seed); | |
treenode tree[] = new treenode[trees] ; | |
for(int k=0;k<trees;k++){ | |
ArrayList<Datapoint> treedata = new ArrayList<Datapoint>() | |
for (int j = 0; j < datapermodel; j++){ | |
//add a random data point to the training data for this tree | |
int nj = Math.abs(rand.nextInt())%data.size(); | |
treedata.add(alldata.get(nj)) ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int splitvariable=-1; // split on this variable | |
double splitvalue ;//split at this value | |
// total positives and negatives used for leaf node probabilities | |
int totalpositives,totalnegatives ; | |
Datapoint trainingdata[]; //the training data in this node | |
treenode leftnode,rightnode;//This node's children if it's a branch | |
//splits this node greedily using approximate information gain | |
public void split(){ | |
double bestscore = Maxvalue ;//lower is better so default is very high number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*A rotation forest algorithm for binary classification with fixed length feature vectors. | |
*created by Alrecenk for inductivebias.com Oct 2013 | |
*/ | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Random; | |
public class RotationForestSimple{ | |
double mean[] ; //the mean of each axis for normalization |
NewerOlder