id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
f8f47f23-cbcf-4a27-b650-6d003ea8f240 | private static double generateNextDouble(double[] expW, double[] expNu, double[] expSigma, Random r){
double rand = r.nextDouble();
int index = 0;
double lower = 0.0, upper = 0.0;
for (int i = 0; i < expW.length && rand != 0.0; i++){
upper += expW[i];
if (lower < rand && rand <= upper){
... |
57ff7cd7-8d73-4d36-bf18-5ba23932524e | private static String asGnuplotFunction(String name, double[] w, double[] nu, double[] sigma) {
StringBuffer ret = new StringBuffer().append(name);
for (int i = 0; i < w.length && i < nu.length && i < sigma.length; i ++) {
if (i == 0) {
ret.append(" = ");
} else {
ret.append(" +... |
86791326-51ca-4c18-8c04-5fb0bdadd15a | private static double[] parseArray(String sArray) {
String[] parts = sArray.split(",");
double[] ret = new double[parts.length];
for (int i = 0; i < parts.length; i ++) {
ret[i] = Double.parseDouble(parts[i]);
}
return ret;
} |
30228e94-3b53-4f8b-9002-2670e0c50b8a | public static void main(String[] args) throws Exception{
if (args.length != 10 && args.length != 11) {
System.err.println("Usage: java -jar gmmtest.jar w1,w2,...,wn m1,m2,...,mn v1,v2,...,vn outputFile tmpDir snapshotStepSize numberOfGeneratedSamples mixtureModelClassName numberOfComponents mixtureModelParams... |
0c7ab5a4-1d42-4de2-817e-dffbb7087167 | public abstract void update(double x); |
c9f686b1-d3dd-4a24-9a6e-b99d2715314f | private void init(int k) {
// update the number of components
this.k = k;
// initialize component weights uniformly
w = new double[k];
Arrays.fill(w, 1.0/((double)k));
// initialize parameters
m = new double[k];
for (int i = 0; i < k; i ++) {
m[i] = ((double)i) - ((double... |
f3532f25-ec55-433c-8e9d-3bef421679ea | protected double computeComponentDensity(int i, double x) {
if (0 <= i && i < k) {
if (w[i] > 0.0) {
double z = (x - m[i]) / v[i];
z *= z;
double ret = w[i] * AbstractGMM.ONE_PER_SQRT2PI * (1.0/v[i]) * Math.exp(-0.5 * z);
//System.out.print("\nx=" + x + ", z=" + z + ", i=" + i ... |
9207d770-67cf-4cba-92ed-b8cc15db5f39 | @Override
public double computeDensityValue(double x) {
double density = 0.0;
// compute the value of density function at x using the current parameters
for (int i = 0; i < k; i ++) {
density += computeComponentDensity(i, x);
}
return density;
} |
ab740f06-0d4a-439d-b01d-19f678482f1f | @Override
public double[] getComponentWeights() {
return w;
} |
5740b09f-5976-4c27-b763-1e715a56441b | @Override
public double[] getComponentMeans() {
return m;
} |
5b69d779-1379-4249-a8dc-1f009e1d6780 | @Override
public double[] getComponentVariances() {
return v;
} |
ed20a0ca-079b-4638-a4a6-390e98b1573c | @Override
public int getNumberOfComponents() {
return k;
} |
163469ff-7547-4563-9926-46a5c7925929 | @Override
public void setNumberOfComponents(int num) {
this.init(num);
} |
7fbf3ebf-69a6-49ed-bef2-5905cca55dd9 | public void update(double x); |
3458536c-016f-4bf4-a3cc-a0d768f21396 | public double computeDensityValue(double x); |
f0964743-1872-4e5a-af3f-1fddced2f32b | public double[] getComponentWeights(); |
e4ed8db5-2408-4682-a1c6-5fdf5813c1c5 | public double[] getComponentMeans(); |
6b1e9ca4-434c-4e0b-b955-16fe92d73262 | public double[] getComponentVariances(); |
4b4e6ddc-51c2-43f4-835a-188e50632b4a | public int getNumberOfComponents(); |
138cf0fc-2760-499e-b3fd-6f702e69ad96 | public void setNumberOfComponents(int num); |
057f0c5b-e81e-48e6-93b8-40428dc42107 | public Map<String,String> parseParameters(String params); |
11a92401-4130-4700-979b-3a38de14c1f1 | public BatchBasedOnlineGMM(int numberOfComponents) {
setNumberOfComponents(numberOfComponents);
pcx = new double[numberOfComponents];
pcx_moments = new double[BatchBasedOnlineGMM.COMPUTED_MOMENTS][numberOfComponents];
} |
4bb5a5f8-4240-4d0e-9066-972af21c8f47 | @Override
public Map<String,String> parseParameters(String params) {
Map<String,String> p = parseParamsToMap(params);
if (p.containsKey("batchSize")) {
batchSize = Integer.parseInt(p.get("batchSize"));
} else {
throw new RuntimeException("Parameter batchSize=someInteger is mandatory for mi... |
5461f35b-30d9-4145-874a-80b844fd65e5 | protected Map<String,String> parseParamsToMap(String params) {
String[] paramsA = params.split("\\s*,\\s*");
Map<String,String> ret = new TreeMap<String,String>();
for (int i = 0; i < paramsA.length; i ++) {
String[] paramValuePair = paramsA[i].split("\\s*=\\s*");
if (paramValuePair.length != 2)... |
2bef4fe2-1956-4213-9fe8-f34a0d06b683 | @Override
public void update(double x) {
// compute the P(C_i|x) = P(C_i|x_c) values for each component
double sumProbs = 0.0;
for (int i = 0; i < k; i ++) {
pcx[i] = computeComponentDensity(i, x);
sumProbs += pcx[i];
}
sumProbs = (sumProbs == 0.0) ? 1.0 : sumProbs; // numeric issue
... |
8cedf6de-5c54-4163-bb1f-ffa92473c5c9 | public static ArrayList<Integer> listOfRandomIntegers(int size) {
ArrayList<Integer> list = new ArrayList<>(size);
for (int i = 0; i <size; i++) {
list.add(Integer.valueOf(RND.nextInt()));
}
return list;
} |
4c42fed9-da7e-40c4-bd09-dbdd38ed65d1 | public static int[] arrayOfRandomInts(int size) {
int[] array = new int[size];
for (int i = 0; i <size; i++) {
array[i] = RND.nextInt();
}
return array;
} |
37548b33-1efa-4eab-a81e-fca4da6dd70c | public static int[] arrayOfGaussiandRandomInts(int size) {
int[] array = new int[size];
for (int i = 0; i <size; i++) {
array[i] = (int) (RND.nextGaussian() * Integer.MAX_VALUE);
}
return array;
} |
bb6be9aa-31b2-46e2-a80f-b3df35ac3a16 | @Setup
public void setup() {
arrayList = DataGenerator.listOfRandomIntegers(size);
linkedList = new LinkedList<>(arrayList);
} |
8a7d92cc-688b-4831-920c-28830a1d322c | @Benchmark
public void forInLoop(Blackhole bh) {
int count = 0;
for (Integer integer : arrayList) {
count += integer.intValue();
}
bh.consume(count);
} |
aa572c29-8a6e-4ac7-a116-68e29ee4f332 | @Benchmark
public void forIndexLoop(Blackhole bh) {
int count = 0;
for (int i = 0; i < arrayList.size(); i++) {
Integer integer = arrayList.get(i);
count += integer.intValue();
}
bh.consume(count);
} |
9ec1337d-0e76-4b6c-a51c-694e73e38e8a | @Benchmark
public void forIndexLinkedLoop(Blackhole bh) {
int count = 0;
for (int i = 0; i < linkedList.size(); i++) {
Integer integer = linkedList.get(i);
count += integer.intValue();
}
bh.consume(count);
} |
ee1c5ab1-c895-4212-8d19-0833f6fa1ab1 | @Benchmark
public void forIndexOptimizedLoop(Blackhole bh) {
int count = 0;
for (int i = 0, arrayListSize = arrayList.size(); i < arrayListSize; i++) {
Integer integer = arrayList.get(i);
count += integer.intValue();
}
bh.consume(count);
} |
07b2fb22-3a24-482c-938e-f22c153d57bc | @Setup
public void setup() {
sineLookup = new SineLookup();
} |
fea7dcfa-ad9d-49d9-918a-54275bf0c84f | @Benchmark
public double math() {
double sum = 0;
for (double input : inputs) {
sum += Math.sin(Math.toRadians(input));
}
return sum;
} |
3a6c8a7f-2d26-4656-8277-53691d3fe7c5 | @Benchmark
public double lookupTable() {
double sum = 0;
for (double input : inputs) {
sum += sineLookup.sin(input);
}
return sum;
} |
ddd1dc1e-a928-4b79-aaab-8b04673e33d2 | public SineLookup() {
for (int i = 0; i < table.length; i++) {
table[i] = Math.sin(Math.toRadians(i));
}
} |
21b30edd-6f8a-449c-a7ce-b0c1b6ad5d79 | public double sin(double degree) {
int d = (int) degree;
d = d % 180;
if (d < 0) {
return -table[d];
}
return table[d];
} |
5405fc03-84c9-4772-91c1-82d4d6b9ba84 | @Setup
public void setup() {
arrayUniformDistribution = DataGenerator.arrayOfRandomInts(1000);
arrayNormalDistribution = DataGenerator.arrayOfGaussiandRandomInts(1000);
} |
48cc6729-397c-400e-b4c1-e6ab7a8329db | @Benchmark
public long newInstance() {
long sum = 0;
for (int i : arrayUniformDistribution) {
Integer integer = new Integer(i);
sum += integer.longValue();
}
return sum;
} |
47dbdcf0-b0e8-4adf-8e8a-7fa24f015db1 | @Benchmark
public long newInstanceGaussian() {
long sum = 0;
for (int i : arrayNormalDistribution) {
Integer integer = new Integer(i);
sum += integer.longValue();
}
return sum;
} |
9f5285ba-be5e-462c-baa8-e76757e4e3fb | @Benchmark
public long valueOf() {
long sum = 0;
for (int i : arrayUniformDistribution) {
Integer integer = Integer.valueOf(i);
sum += integer.longValue();
}
return sum;
} |
e869ff8e-9683-4af7-86ba-ce5f9cd58990 | @Benchmark
public long valueOfGaussian() {
long sum = 0;
for (int i : arrayNormalDistribution) {
Integer integer = Integer.valueOf(i);
sum += integer.longValue();
}
return sum;
} |
be09cb9e-c7a8-4205-a035-759aa9e2ea66 | @Benchmark
public String[] usingNew() {
return new String[1];
} |
2853cd4f-0126-4e49-9b09-212480921896 | @Benchmark
public String[] reflection() {
return (String[]) Array.newInstance(String.class, 1);
} |
b0f221a5-7c0b-4726-905e-5feae723c976 | @Benchmark
public String[] cloneKnownType() {
return ARR.clone();
} |
bfefa60e-8a0d-4abf-88df-71ef1800315c | public CountdownTimer (CountdownTimerListener listener, Participant p, int msecs) {
this.listener = listener;
this.p = p;
timer = new Timer(msecs, this);
timer.start();
} |
b8c45b1d-6235-4811-a1a9-10b90c5935eb | @Override
public void actionPerformed(ActionEvent e) {
timer.stop();
listener.timeExpired(p);
} |
967fff5b-0b67-45c8-b0f2-b0a5d3864c0f | public TransitionTimer (int msecs, int transitionCount, Controller controller) {
this.transitionCount = transitionCount;
this.controller = controller;
timer = new Timer(msecs, this);
timer.addActionListener(this);
timer.start();
} |
88e62735-9f49-4d3b-b1cf-1e10a7935153 | @Override
public void actionPerformed (ActionEvent e) {
timer.stop();
if (controller.getTransitionCount() == transitionCount) {
controller.performTransition();
}
} |
d3290a7c-f5c6-4c34-ab4a-3cbc45e2ad59 | public void collidedWith (Participant p1, Participant p2); |
cae5fc7f-7817-43f1-a33c-9405de61de8c | public Ship () {
appended = false;
thrust = false;
poly = new Path2D.Double();
poly.moveTo(20, 0);
poly.lineTo(-20, 12);
poly.lineTo(-12, 0);
poly.lineTo(-20, -12);
poly.closePath();
outline = poly;
} |
619a1f72-d8ac-4954-878d-3132c7afa6e9 | public void setOppositeThrust () {
if (thrust)
thrust = false;
else
thrust = true;
} |
7ab658f8-2e13-4326-983e-151a2459eafe | public void setThrust (boolean b) {
thrust = b;
} |
3c0bcfc8-699c-4f57-a70a-538416fead55 | public double getXNose () {
Point2D.Double point = new Point2D.Double(20, 0);
transformPoint(point);
return point.getX();
} |
c8a97701-f0b4-4dc2-a322-0c615a59e343 | public double getYNose () {
Point2D.Double point = new Point2D.Double(20, 0);
transformPoint(point);
return point.getY();
} |
fd8cac8e-1a50-4c71-8b24-a5d4df522b20 | @Override
protected Shape getOutline () {
return outline;
} |
eb97b0da-0b5f-43ca-bf75-7e13c3ff18e9 | @Override
public void move () {
super.move();
friction();
} |
38e6e398-079b-4615-8d50-124268fbd6ad | @Override
public void draw(Graphics2D g) {
Path2D.Double thruster = new Path2D.Double();
thruster.moveTo(-16, 6);
thruster.lineTo(-24, 0);
thruster.lineTo(-16, -6);
if (thrust && appended == false) {
poly.append(thruster.getPathIterator(null), false);
appended = true;
outline = poly;
}
else if (... |
1bf3e1a9-38fa-48a3-8b26-5148017d4be9 | public Star (double x, double y) {
setPosition(x,y);
new CountdownTimer(this,this,random.nextInt(7000));
outline = e;
} |
771621d1-c3b4-40f2-8c81-641bb351c3be | @Override
Shape getOutline() {
return outline;
} |
e10ec767-a574-4621-b694-8439fa079a6a | @Override
public void timeExpired(Participant p) {
if ( e.getHeight() == 1) {
e.setFrame(e.getX(), e.getY(), 0, 0);
new CountdownTimer(this,p,50);
}
else {
e.setFrame(e.getX(), e.getY(), 1, 1);
new CountdownTimer(this,p,2000 +random.nextInt(7000));
}
} |
bd8905ec-b25d-4521-9773-adeec4859607 | protected Participant () {
speedX = 0;
speedY = 0;
rotation = 0;
x = 0;
y = 0;
border = null;
} |
f82dd098-b4f5-489a-b088-c7d84d30aab4 | public void setVelocity (double speed, double direction) {
this.speed = speed;
speedX = Math.cos(direction) * speed;
speedY = Math.sin(direction) * speed;
} |
373aa834-bc1a-4e13-8dfc-82255dcda5bc | public double getVelocity() {
return speed;
} |
e0cdd10b-5ea8-4d63-a61c-b643c82800db | public void setRotation (double radians) {
rotation = radians;
} |
ab7ed3c2-18d6-429e-9fbf-e50718d48b61 | public void rotate (double delta) {
rotation += delta;
} |
5dfdae92-1669-482a-aab6-b79045f97597 | public double getRotation () {
return rotation;
} |
501eb223-5b9f-482b-901a-5ab795661c93 | public void accelerate (double delta) {
double deltaX = delta*Math.cos(rotation);
double deltaY = delta*Math.sin(rotation);
speedX += deltaX;
speedY += deltaY;
if (Math.sqrt(speedX*speedX + speedY*speedY) > SPEED_LIMIT) {
speedX -= deltaX;
speedY -= deltaY;
}
} |
e045946f-e69f-43f1-866f-2dad58afb0f8 | public void friction () {
if (speedX != 0 || speedY != 0) {
double deltaX = FRICTION * speedX / Math.sqrt(speedX*speedX + speedY*speedY);
double deltaY = FRICTION * speedY / Math.sqrt(speedX*speedX + speedY*speedY);
if (Math.abs(deltaX) > Math.abs(speedX) || Math.abs(deltaY) > Math.abs(speedY)) {
speedX ... |
bae62440-9d0d-45ac-b680-3ab5efd75b71 | public void setPosition (double x, double y) {
this.x = x;
this.y = y;
} |
de624413-ac02-4160-8620-cf9b14686a16 | public double getX () {
return x;
} |
175977c6-ad43-448f-b1ba-6bec25a856fa | public double getY () {
return y;
} |
4d209257-5a4c-49f6-89fd-d137e0912fc2 | abstract Shape getOutline (); |
d225640f-0c2f-4d73-8f56-7cdcf7085d38 | public void move () {
// Get the original outline
Shape original = getOutline();
// Change the position to reflect participant motion
x += speedX;
y += speedY;
// Translate and rotate the original to reflect the accumulated motion
AffineTransform trans = AffineTransform.getTranslateInstance(x,y);... |
665ad3c6-e5cf-46fa-98b9-00186bcfff25 | public void transformPoint (Point2D.Double point) {
AffineTransform trans = AffineTransform.getTranslateInstance(x,y);
trans.concatenate(AffineTransform.getRotateInstance(rotation));
trans.transform(point, point);
} |
887ac6e0-d0ba-4dc5-88f1-7a9d89e0c217 | public boolean overlaps (Participant p) {
Area a = new Area(border);
a.intersect(new Area(p.border));
return !a.isEmpty();
} |
8591431c-3cbe-4104-a4ab-0c5b4dcb3c52 | public void draw (Graphics2D g) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (border == null) {
border = getOutline();
}
g.draw(border);
} |
fc7eed15-f1c9-4013-a65c-47867cf4461e | public static void main (String[] args) {
Game a = new Game();
a.setVisible(true);
} |
72406b76-49ce-4986-a24c-fc2134639bc4 | public Game () {
// Title at the top
setTitle(TITLE);
// Default behavior on closing
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// The main playing area and the controller
Screen screen = new Screen();
Controller controller = new Controller(this, screen);
// This panel contains the scr... |
a244189f-f656-4cc1-82b0-cde2a38db877 | public void setScore(int s) {
score.setText("Score: " + s);
} |
58322d17-842a-44d3-982c-997393972f83 | public void setLives(int l) {
lives.setText("Lives: " + l);
} |
a067eb48-01e8-4a0c-8cac-f0c37dd73bd3 | public Debris (int type, double x, double y) {
Shape e;
if (type == 1) {
e = new Path2D.Double();
((Path2D) e).moveTo(-20, 12);
((Path2D) e).lineTo(-12, 0);
setVelocity( random.nextDouble(), random.nextDouble());
}
else {
e = new Ellipse2D.Double(0, 0, 1, 1);
setVelocity(1 + rand... |
31dde68e-4f41-4279-bd01-ae63d310f102 | @Override
Shape getOutline() {
return outline;
} |
d69d2b35-0c0e-4d68-932f-1d68c1ec6398 | public AlienShip () {
Ellipse2D.Double e = new Ellipse2D.Double(0,0,40, 5);
outline = e;
} |
0ce60cd1-076e-48a5-a912-378f51e5ccef | public double getXNose () {
Point2D.Double point = new Point2D.Double(20, 0);
transformPoint(point);
return point.getX();
} |
2993ec08-20f0-4228-95c6-e14c5ed86ee9 | public double getYNose () {
Point2D.Double point = new Point2D.Double(20, 0);
transformPoint(point);
return point.getY();
} |
93c9f205-b535-4280-a490-60c381a2581c | @Override
protected Shape getOutline () {
return outline;
} |
89b9766a-1793-404c-9911-ad5c1eea6535 | public void timeExpired (Participant p); |
93e35cec-4c35-4495-bf99-3cdce449ee6b | public Screen () {
participants = new LinkedList<Participant>();
listeners = new HashSet<CollisionListener>();
pendingAdds = new HashSet<Participant>();
pendingRemoves = new HashSet<Participant>();
legend = "";
setPreferredSize(new Dimension(SIZE, SIZE));
setMinimumSize(new Dimension(SIZE, SIZE));
setBa... |
bcd6e526-c164-4d55-9db3-7941b2deae12 | public void addParticipant (Participant p) {
pendingAdds.add(p);
} |
87ec52ab-cba1-41b9-853c-ac7c6faa87f3 | public void removeParticipant(Participant p) {
pendingRemoves.add(p);
} |
8bd18625-6993-485f-aa9b-bd52631c492f | public void setLegend (String legend) {
this.legend = legend;
} |
41c5da22-5c91-4466-9407-db57ace785f6 | @Override
public void paintComponent (Graphics g) {
// Do the default painting
super.paintComponent(g);
// Draw each participant in its proper place
for (Participant e: participants) {
e.draw((Graphics2D) g);
}
// Draws the legend across the middle of the panel
int size = g.getFontMetrics().... |
e42bea7c-18a8-4a43-b496-d3e6a26999af | public void clear () {
pendingRemoves.clear();
pendingAdds.clear();
participants.clear();
legend = "";
} |
b60a2eac-9eec-414c-a395-89fc1c343177 | public void addCollisionListener (CollisionListener listener) {
listeners.add(listener);
} |
682beb10-7a5f-4eb7-91a6-c2566659e25c | public void removeCollisionListener (CollisionListener listener) {
listeners.remove(listener);
} |
9e561889-58d9-4a26-86f8-b6f0d482c36e | private void checkForCollisions () {
for (Participant p1: participants) {
Iterator<Participant> iter = participants.descendingIterator();
while (iter.hasNext()) {
Participant p2 = iter.next();
if (p2 == p1) break;
if (pendingRemoves.contains(p1)) break;
if (pendingRemoves.contains(p2)) break;
... |
48c3acea-f4f2-4740-ab2c-d0e08dd1bd9e | private void completeAddsAndRemoves () {
// Note: These updates are saved up done later to avoid modiying
// the participants list while it is being iterated over
for (Participant p: pendingAdds) {
participants.add(p);
}
pendingAdds.clear();
for (Participant p: pendingRemoves) {
participants.remove... |
ed93a76a-937a-4fa3-bad4-eb7bbda11d0b | public void refresh () {
completeAddsAndRemoves();
for (Participant p: participants) {
p.move();
}
checkForCollisions();
repaint();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.