Skip to content

Commit

Permalink
yoyoyo
Browse files Browse the repository at this point in the history
  • Loading branch information
TheColdIce committed Oct 3, 2023
1 parent 3efd5df commit e3603a2
Show file tree
Hide file tree
Showing 34 changed files with 382 additions and 744 deletions.
6 changes: 6 additions & 0 deletions AMLsim/paramFiles/1K_accts_super_easy/conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"std_amount": 10,
"mean_amount_sar": 10000,
"std_amount_sar": 10,
"prob_income": 0.1,
"mean_income": 1000,
"std_income": 100,
"prob_income_sar": 0.2,
"mean_income_sar": 2000,
"std_income_sar": 200,
"mean_phone_change_frequency": 1460,
"std_phone_change_frequency": 365,
"mean_phone_change_frequency_sar": 365,
Expand Down
Binary file added AMLsim/salary_distribution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion AMLsim/scripts/transaction_graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ def count__patterns(self, threshold=2):
if __name__ == "__main__":
argv = sys.argv
# debug:
PARAM_FILES = '10K_accts_super_easy'
PARAM_FILES = '1K_accts_super_easy'
argv.append(f'paramFiles/{PARAM_FILES}/conf.json')
argc = len(argv)
if argc < 2:
Expand Down
2 changes: 1 addition & 1 deletion AMLsim/src/main/java/amlsim/AMLSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public static void main(String[] args) {

// Loading configuration JSON file instead of parsing command line arguments
// String confFile = args[0];
String paramFiles = "10K_accts_super_easy";
String paramFiles = "1K_accts_super_easy";
String confFile = "paramFiles/" + paramFiles + "/conf.json"; // debug

try {
Expand Down
20 changes: 17 additions & 3 deletions AMLsim/src/main/java/amlsim/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sim.engine.Steppable;
import java.util.*;
import amlsim.dists.TruncatedNormal;
import amlsim.dists.salarydist.SalaryDistribution;
import amlsim.AccountBehaviour;

public class Account implements Steppable {
Expand All @@ -24,6 +25,13 @@ public class Account implements Steppable {
private int numSARBene = 0; // Number of SAR beneficiary accounts
private String bankID = ""; // Bank ID

private double monthlyIncome = 0; // Salary
private double monthlyOutcome = 0; // Rent
private double meanIncome = 0; // Mean income
private double stdIncome = 0; // Standard deviation of income
private double meanOutcome = 0; // Mean outcome
private double stdOutcome = 0; // Standard deviation of outcome

private Account prevOrig = null; // Previous originator account
private Account debtor = null; // Previous beneficiary account
private double debt = 0; // Amount of money owed to the previous beneficiary account
Expand Down Expand Up @@ -74,10 +82,10 @@ public Account(String id, int interval, float initBalance, String bankID, Random
this.cashOutModel.setParameters(interval, -1, -1);

this.accountBehaviour = new AccountBehaviour(this.isSAR);

// TODO: Set salary
// this.salary = new TruncatedNormal(0, 0, 0, 0);

this.monthlyIncome = new SalaryDistribution().sample();
// TODO: set rent
// this.rent = new TruncatedNormal(0, 0, 0, 0);
}
Expand Down Expand Up @@ -230,7 +238,13 @@ public void step(SimState state) {
long end = this.endStep > 0 ? this.endStep : AMLSim.getNumOfSteps();

// TODO: Handle salary, if 25th of the month, deposit salary
if (currentStep % 28 == 25) {
this.deposit(this.monthlyIncome);
}

// TODO: Handle income


// TODO: Handle monthly expense, if 26th to 28th of the month, pay monthly expense
// TODO: Handle smallar expenses
this.bankID = this.accountBehaviour.getNewBank(this.bankID);
Expand Down
57 changes: 57 additions & 0 deletions AMLsim/src/main/java/amlsim/SimProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public class SimProperties {
private double meanBankChangeFrequencySAR;
private double stdBankChangeFrequencySAR;

// Income and outcome parameters
private double probIncome;
private double meanIncome;
private double stdIncome;
private double probIncomeSAR;
private double meanIncomeSAR;
private double stdIncomeSAR;
//private double probOutcome;
//private double meanOutcome;
//private double stdOutcome;
//private double probOutcomeSar;
//private double meanOutcomeSar;
//private double stdOutcomeSar;

SimProperties(String jsonName) throws IOException {
String jsonStr = loadTextFile(jsonName);
JSONObject jsonObject = new JSONObject(jsonStr);
Expand Down Expand Up @@ -71,6 +85,13 @@ public class SimProperties {
meanBankChangeFrequencySAR = defaultProp.getDouble("mean_bank_change_frequency_sar");
stdBankChangeFrequencySAR = defaultProp.getDouble("std_bank_change_frequency_sar");

probIncome = defaultProp.getDouble("prob_income");
meanIncome = defaultProp.getDouble("mean_income");
stdIncome = defaultProp.getDouble("std_income");
probIncome = defaultProp.getDouble("prob_income_sar");
meanIncome = defaultProp.getDouble("mean_income_sar");
stdIncome = defaultProp.getDouble("std_income_sar");

System.out.printf("General transaction interval: %d\n", normalTxInterval);
System.out.printf("Base transaction amount: Normal = %f, Suspicious= %f\n", minTxAmount, maxTxAmount);

Expand Down Expand Up @@ -179,6 +200,42 @@ public double getStdBankChangeFrequencySAR() {
return stdBankChangeFrequencySAR;
}

public double getProbIncome() {
return probIncome;
}

public double getMeanIncome() {
return meanIncome;
}

public double getStdIncome() {
return stdIncome;
}

public double getProbIncomeSAR() {
return probIncomeSAR;
}

public double getMeanIncomeSAR() {
return meanIncomeSAR;
}

public double getStdIncomeSAR() {
return stdIncomeSAR;
}

//public double getProbOutcome() {
// return probOutcome;
//}
//
//public double getMeanOutcome() {
// return meanOutcome;
//}
//
//public double getStdOutcome() {
// return stdOutcome;
//}

public double getMarginRatio() {
return marginRatio;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.opencsv.exceptions.CsvValidationException;

import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.commons.math3.distribution.LogNormalDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;

import java.io.FileReader;
Expand All @@ -17,9 +18,13 @@ public class SalaryDistribution {
private List<SalaryInfo> salaryInfos;
private double[] cumulativeProbabilities;

public SalaryDistribution(String csvFilePath) throws IOException {
public SalaryDistribution() {
salaryInfos = new ArrayList<>();
readCSV(csvFilePath);
try {
readCSV("src/main/java/amlsim/dists/salarydist/scb_statistics_2021.csv");
} catch (IOException e) {
e.printStackTrace();
}
computeCumulativeProbabilities();
}

Expand Down Expand Up @@ -68,13 +73,16 @@ public double sample() {
}

double mean = salaryInfos.get(ageIndex).getAverageYearIncome();
double variance = 50.0;

double median = salaryInfos.get(ageIndex).getMedianYearIncome();
double mu = Math.log(median);
double sigma = Math.sqrt(2 * Math.abs(Math.log(mean) - mu));

JDKRandomGenerator rng = new JDKRandomGenerator();
NormalDistribution normal = new NormalDistribution(rng, mean, Math.sqrt(variance));

return normal.sample();
//NormalDistribution normal = new NormalDistribution(rng, mean, Math.sqrt(variance));
LogNormalDistribution normal = new LogNormalDistribution(rng, mu, sigma);
double salary = normal.sample() * 1000 / 12;

return salary;
}

// SalaryInfo class remains the same...
}
43 changes: 20 additions & 23 deletions AMLsim/src/main/java/amlsim/dists/salarydist/TestScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,35 @@
public class TestScript {

public static void main(String[] args) {
String path = "/home/edvin/Desktop/flib/AMLsim/src/main/java/amlsim/dists/salarydist/scb_statistics_2021.csv";
try {
SalaryDistribution distribution = new SalaryDistribution(path);
SalaryDistribution distribution = new SalaryDistribution();

int sampleSize = 1000000; // Sample 10,000 times, adjust as needed
List<Double> samples = new ArrayList<>();
int sampleSize = 1000000; // Sample 10,000 times, adjust as needed
List<Double> samples = new ArrayList<>();

for (int i = 0; i < sampleSize; i++) {
samples.add(distribution.sample());
}
for (int i = 0; i < sampleSize; i++) {
samples.add(distribution.sample());
}

// Convert samples to a primitive array
double[] primitiveSamples = samples.stream().mapToDouble(Double::doubleValue).toArray();
// Convert samples to a primitive array
double[] primitiveSamples = samples.stream().mapToDouble(Double::doubleValue).toArray();

HistogramDataset dataset = new HistogramDataset();
dataset.addSeries("Salary Distribution", primitiveSamples, 50); // 50 bins, adjust as needed
HistogramDataset dataset = new HistogramDataset();
dataset.addSeries("Salary Distribution", primitiveSamples, 100); // 50 bins, adjust as needed

JFreeChart histogram = ChartFactory.createHistogram(
"Salary Distribution",
"Salary",
"Frequency",
dataset
);
JFreeChart histogram = ChartFactory.createHistogram(
"Salary Distribution",
"Salary",
"Frequency",
dataset
);

// Save the histogram as a PNG image
File outputFile = new File("salary_distribution.png");
// Save the histogram as a PNG image
File outputFile = new File("salary_distribution.png");
try {
ChartUtils.saveChartAsPNG(outputFile, histogram, 800, 600); // Width: 800, Height: 600, adjust as needed

System.out.println("Histogram saved to: " + outputFile.getAbsolutePath());

} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Histogram saved to: " + outputFile.getAbsolutePath());
}
}
Binary file modified AMLsim/target/classes/amlsim/SimProperties.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/TargetedTransactionAmount.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/dists/NormalDist.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/dists/NormalDistQuick.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/dists/Num.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/dists/TruncatedNormal.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/dists/TruncatedNormalQuick.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/BipartiteTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/CycleTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/FanInTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/FanOutTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/GatherScatterTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/RandomTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/ScatterGatherTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/StackTypology.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added datasets/1K_accts_super_easy/raw/tx_log.parquet
Binary file not shown.
Binary file modified salary_distribution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e3603a2

Please sign in to comment.