Skip to content

Commit

Permalink
fixed so txs are (more) uniformly distributed over steps
Browse files Browse the repository at this point in the history
  • Loading branch information
TheColdIce committed Nov 9, 2023
1 parent 837c6bb commit 3b16498
Show file tree
Hide file tree
Showing 5 changed files with 415 additions and 11 deletions.
29 changes: 20 additions & 9 deletions AMLsim/src/main/java/amlsim/AccountGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,28 @@ public class AccountGroup {
assert startStep < endStep : "startStep must be smaller than endStep";
assert interval > 0 : "interval must be positive";

if (startStep >= 0 && startStep < AMLSim.getNumOfSteps()) {
int range = (int) (endStep - startStep + 1);
this.startStep = AMLSim.getRandom().nextInt(range) + startStep;
} else {
this.startStep = AMLSim.getRandom().nextInt((int) AMLSim.getNumOfSteps() - 1);
//if (startStep >= 0 && startStep < AMLSim.getNumOfSteps()) {
// int range = (int) (endStep - startStep + 1);
// this.startStep = AMLSim.getRandom().nextInt(range) + startStep;
//} else {
// this.startStep = AMLSim.getRandom().nextInt((int) AMLSim.getNumOfSteps() - 1);
//}
//
//if (endStep >= 0 && endStep < AMLSim.getNumOfSteps()) {
// this.endStep = endStep;
//} else {
// this.endStep = AMLSim.getNumOfSteps();
//}

long s1 = startStep + AMLSim.getRandom().nextInt((int) (endStep - startStep + 1));
long s2 = startStep + AMLSim.getRandom().nextInt((int) (endStep - startStep + 1));
this.startStep = Math.min(s1, s2);
this.endStep = Math.max(s1, s2);
if (this.startStep < startStep) {
this.startStep = startStep;
}

if (endStep >= 0 && endStep < AMLSim.getNumOfSteps()) {
if (this.endStep > endStep) {
this.endStep = endStep;
} else {
this.endStep = AMLSim.getNumOfSteps();
}

this.scheduleID = scheduleID;
Expand Down
1 change: 1 addition & 0 deletions transaction-network-explorer/TransactionNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, path:str) -> None:

def load_data(self, path:str) -> pd.DataFrame:
df = pd.read_csv(path)
df = df.loc[df['type']!='CASH']
return df

def format_data(self, df:pd.DataFrame) -> pd.DataFrame:
Expand Down
Binary file not shown.
110 changes: 110 additions & 0 deletions transaction-network-explorer/test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>step</th>\n",
" <th>acct</th>\n",
" <th>amt</th>\n",
" <th>bal</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>a</td>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>1</td>\n",
" <td>a</td>\n",
" <td>-10</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5</td>\n",
" <td>a</td>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" step acct amt bal\n",
"0 0 a 10 10\n",
"5 1 a -10 0\n",
"1 5 a 10 10"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"steps = [0, 5, 2, 3, 4, 1]\n",
"accts = ['a', 'a', 'b', 'b', 'b', 'a']\n",
"amts = [10, 10, 10, -10, 10, -10]\n",
"df = pd.DataFrame({'step': steps, 'acct': accts, 'amt': amts})\n",
"\n",
"df = df.sort_values(by=['step'])\n",
"df['bal'] = df.groupby('acct')['amt'].cumsum()\n",
"\n",
"df[df['acct']=='a']\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "tne-cpu",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 3b16498

Please sign in to comment.