[JAVA-22519] Move articles from generic libraries module to specific library modules (#15416)
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package com.baeldung.jmh;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
|
||||
public class BenchMark {
|
||||
|
||||
@Benchmark
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.baeldung.jmh;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.openjdk.jmh.Main;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
|
||||
public class JmhDemo {
|
||||
public static void main(String[] args) throws RunnerException, IOException {
|
||||
Main.main(args);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.baeldung.jmh.warmup;
|
||||
|
||||
public class MainApplication {
|
||||
|
||||
static {
|
||||
long start = System.nanoTime();
|
||||
ManualClassLoader.load();
|
||||
long end = System.nanoTime();
|
||||
System.out.println("Warm Up time : " + (end - start));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long start = System.nanoTime();
|
||||
ManualClassLoader.load();
|
||||
long end = System.nanoTime();
|
||||
System.out.println("Total time taken : " + (end - start));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.baeldung.jmh.warmup;
|
||||
|
||||
import com.baeldung.jmh.warmup.dummy.Dummy;
|
||||
|
||||
public class ManualClassLoader {
|
||||
|
||||
public static void load() {
|
||||
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
// load all(or most) important classes
|
||||
Dummy dummy = new Dummy();
|
||||
dummy.m();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.baeldung.jmh.warmup.dummy;
|
||||
|
||||
public class Dummy {
|
||||
|
||||
public void m() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.baeldung.neuroph;
|
||||
|
||||
import org.neuroph.core.Layer;
|
||||
import org.neuroph.core.NeuralNetwork;
|
||||
import org.neuroph.core.Neuron;
|
||||
import org.neuroph.core.data.DataSet;
|
||||
import org.neuroph.core.data.DataSetRow;
|
||||
import org.neuroph.nnet.learning.BackPropagation;
|
||||
import org.neuroph.util.ConnectionFactory;
|
||||
import org.neuroph.util.NeuralNetworkType;
|
||||
|
||||
public class NeurophXOR {
|
||||
|
||||
public static NeuralNetwork assembleNeuralNetwork() {
|
||||
|
||||
Layer inputLayer = new Layer();
|
||||
inputLayer.addNeuron(new Neuron());
|
||||
inputLayer.addNeuron(new Neuron());
|
||||
|
||||
Layer hiddenLayerOne = new Layer();
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
hiddenLayerOne.addNeuron(new Neuron());
|
||||
|
||||
Layer hiddenLayerTwo = new Layer();
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
hiddenLayerTwo.addNeuron(new Neuron());
|
||||
|
||||
Layer outputLayer = new Layer();
|
||||
outputLayer.addNeuron(new Neuron());
|
||||
|
||||
NeuralNetwork ann = new NeuralNetwork();
|
||||
|
||||
ann.addLayer(0, inputLayer);
|
||||
ann.addLayer(1, hiddenLayerOne);
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(1));
|
||||
ann.addLayer(2, hiddenLayerTwo);
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(1), ann.getLayerAt(2));
|
||||
ann.addLayer(3, outputLayer);
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(2), ann.getLayerAt(3));
|
||||
ConnectionFactory.fullConnect(ann.getLayerAt(0), ann.getLayerAt(ann.getLayersCount() - 1), false);
|
||||
|
||||
ann.setInputNeurons(inputLayer.getNeurons());
|
||||
ann.setOutputNeurons(outputLayer.getNeurons());
|
||||
|
||||
ann.setNetworkType(NeuralNetworkType.MULTI_LAYER_PERCEPTRON);
|
||||
return ann;
|
||||
}
|
||||
|
||||
public static NeuralNetwork trainNeuralNetwork(NeuralNetwork ann) {
|
||||
int inputSize = 2;
|
||||
int outputSize = 1;
|
||||
DataSet ds = new DataSet(inputSize, outputSize);
|
||||
|
||||
DataSetRow rOne = new DataSetRow(new double[] { 0, 1 }, new double[] { 1 });
|
||||
ds.addRow(rOne);
|
||||
DataSetRow rTwo = new DataSetRow(new double[] { 1, 1 }, new double[] { 0 });
|
||||
ds.addRow(rTwo);
|
||||
DataSetRow rThree = new DataSetRow(new double[] { 0, 0 }, new double[] { 0 });
|
||||
ds.addRow(rThree);
|
||||
DataSetRow rFour = new DataSetRow(new double[] { 1, 0 }, new double[] { 1 });
|
||||
ds.addRow(rFour);
|
||||
|
||||
BackPropagation backPropagation = new BackPropagation();
|
||||
backPropagation.setMaxIterations(1000);
|
||||
|
||||
ann.learn(ds, backPropagation);
|
||||
return ann;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.baeldung.stm;
|
||||
|
||||
import org.multiverse.api.StmUtils;
|
||||
import org.multiverse.api.callables.TxnCallable;
|
||||
import org.multiverse.api.references.TxnInteger;
|
||||
import org.multiverse.api.references.TxnLong;
|
||||
|
||||
public class Account {
|
||||
|
||||
private final TxnLong lastUpdate;
|
||||
private final TxnInteger balance;
|
||||
|
||||
Account(final int balance) {
|
||||
this.lastUpdate = StmUtils.newTxnLong(System.currentTimeMillis());
|
||||
this.balance = StmUtils.newTxnInteger(balance);
|
||||
}
|
||||
|
||||
Integer getBalance() {
|
||||
return balance.atomicGet();
|
||||
}
|
||||
|
||||
void adjustBy(final int amount) {
|
||||
adjustBy(amount, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private void adjustBy(final int amount, final long date) {
|
||||
StmUtils.atomic(() -> {
|
||||
balance.increment(amount);
|
||||
lastUpdate.set(date);
|
||||
|
||||
if (balance.get() < 0) {
|
||||
throw new IllegalArgumentException("Not enough money");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void transferTo(final Account other, final int amount) {
|
||||
StmUtils.atomic(() -> {
|
||||
final long date = System.currentTimeMillis();
|
||||
adjustBy(-amount, date);
|
||||
other.adjustBy(amount, date);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return StmUtils.atomic((TxnCallable<String>) txn -> "Balance: " + balance.get(txn) + " lastUpdateDate: " + lastUpdate.get(txn));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user