Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Lewis model #58

Merged
merged 61 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
8502fd1
Add skeleton lei stuff
JamesYang007 Jul 18, 2022
ff64166
Add lei notebook for now and poisson process fun study
JamesYang007 Aug 1, 2022
587de21
Add stuff for ben to see
JamesYang007 Aug 2, 2022
b49f8cd
Add current changes for Ben once again (so needy :P)
JamesYang007 Aug 2, 2022
bfa8933
Fixed the hang problem.
tbenthompson Aug 3, 2022
6a852c5
Commit what I have
JamesYang007 Aug 3, 2022
8e6c145
Merge branch 'james.yang/lei' of https://github.com/Confirm-Solutions…
JamesYang007 Aug 3, 2022
0c16de4
Add currently broken code once again
JamesYang007 Aug 3, 2022
255f536
Simplify notebook
JamesYang007 Aug 3, 2022
508de87
Add working version of lewis
JamesYang007 Aug 3, 2022
02d98e5
Add current progress
JamesYang007 Aug 17, 2022
d5ad8c2
Add batching method and current logic of lei
JamesYang007 Aug 18, 2022
44f1b75
Move lei stuff to its own package
JamesYang007 Aug 18, 2022
fcb2e55
Working on linear interpolation for the Lei problem.
tbenthompson Aug 18, 2022
619ce2e
Merge branch 'main' into james.yang/lei
tbenthompson Aug 18, 2022
c7e83d1
inlaw -> outlaw.
tbenthompson Aug 18, 2022
8c55d4b
Add lei test n_config
JamesYang007 Aug 18, 2022
269c3ba
Merge branch 'james.yang/lei' of https://github.com/Confirm-Solutions…
JamesYang007 Aug 18, 2022
7538749
Fix settings.json
JamesYang007 Aug 18, 2022
924c8d9
Add unit tests and update notebook with correct simulations
JamesYang007 Aug 20, 2022
cc217c8
Update test, add simulation tests, add point batcher, share RNG
JamesYang007 Aug 21, 2022
aef4084
Update comment
JamesYang007 Aug 21, 2022
9acece2
JAX implementation of scipy.interpolate.interpn (#47)
tbenthompson Aug 21, 2022
0fad334
Add current version lol
JamesYang007 Aug 23, 2022
14c947f
Fix bugs and integrate good version
JamesYang007 Aug 24, 2022
4174779
Fix small bug in stage 2 and clean up code
JamesYang007 Aug 24, 2022
39b6ae1
Modify interpn to work with multi-dimensional values
JamesYang007 Aug 24, 2022
854ee4e
Add current version of notebook
JamesYang007 Aug 24, 2022
96579bf
WTF
JamesYang007 Aug 24, 2022
5e8c3ff
Finish final lei
JamesYang007 Aug 25, 2022
297a14a
Fix test in outlaw
JamesYang007 Aug 25, 2022
78e2b63
Merge branch 'main' into james.yang/lei
JamesYang007 Aug 25, 2022
f37715b
Add python notebook (weird vscode lol)
JamesYang007 Aug 25, 2022
55660d1
Add lei simulator batching method
JamesYang007 Aug 25, 2022
edc84d4
Remove unnecessary files cluttering up space
JamesYang007 Aug 29, 2022
ae31195
Add current state
JamesYang007 Aug 30, 2022
3004931
Add upper bound logic to lei example
JamesYang007 Sep 8, 2022
cc197fc
Add ignore to frontend and update lei flow
JamesYang007 Sep 8, 2022
215e736
Clean up lewis code and include some of Ben's changes
JamesYang007 Sep 9, 2022
f552b50
Merge branch 'main' into james.yang/lei
JamesYang007 Sep 9, 2022
5e58c74
Merge branch 'main' into james.yang/lei
JamesYang007 Sep 10, 2022
6317421
Add new script
JamesYang007 Sep 10, 2022
b0d7520
Add new changes to make memory ok
JamesYang007 Sep 11, 2022
e7ee4f7
Add full changes to everything except key
JamesYang007 Sep 11, 2022
10a30f2
Add checkpointing
JamesYang007 Sep 11, 2022
116431a
Add modified version
JamesYang007 Sep 12, 2022
dddbedf
Merge branch 'james.yang/lei' of https://github.com/Confirm-Solutions…
JamesYang007 Sep 12, 2022
c496511
First pass at holder-odi bound in binomial.py
tbenthompson Sep 20, 2022
440fb38
Holder-ODI, feeling more confident.
tbenthompson Sep 20, 2022
0004a26
Add analyze lei example
JamesYang007 Sep 20, 2022
16b2ef9
Merge branch 'main' into james.yang/lei
JamesYang007 Sep 20, 2022
c4b48db
Move lewis into confirm
JamesYang007 Sep 20, 2022
fe145a8
Fix analyze notebook with new import structure
JamesYang007 Sep 20, 2022
87eb48d
Merge branch 'tbt/holderodi' into james.yang/lei
JamesYang007 Sep 20, 2022
04fedc6
Add np.isnan check for holder bound and update lei analyze scripts
JamesYang007 Sep 21, 2022
6d5beae
Moving files, small tweaks.
tbenthompson Sep 27, 2022
8283901
Merge branch 'main' into james.yang/lei
tbenthompson Sep 27, 2022
04c072f
Pre-commit fixes.
tbenthompson Sep 27, 2022
24a44fc
Merge branch 'main' into james.yang/lei
tbenthompson Sep 27, 2022
9b7ed31
Most tests passing.
tbenthompson Sep 27, 2022
07e1cb1
Fix test stage1.
tbenthompson Sep 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
"justMyCode": false,
}
]
}
249 changes: 124 additions & 125 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,127 +1,126 @@
{
"bazel-cpp-tools.compileCommands.targets": [
"//...",
],
"jupyter.jupyterServerType": "local",
"files.associations": {
"functional": "cpp",
"*.evaluator": "cpp",
"*.traits": "cpp",
"fft": "cpp",
"openglsupport": "cpp",
"regex": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"utility": "cpp",
"hash_map": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"filesystem": "cpp",
"locale": "cpp",
"mprealsupport": "cpp",
"nonlinearoptimization": "cpp",
"dense": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"compare": "cpp",
"concepts": "cpp",
"ios": "cpp",
"queue": "cpp",
"stack": "cpp",
"__functional_base": "cpp",
"alignedvector3": "cpp",
"typeindex": "cpp",
"*.ipp": "cpp",
"*.inc": "cpp",
"core": "cpp",
"geometry": "cpp",
"qtalignedmalloc": "cpp",
"matrixfunctions": "cpp",
"bvh": "cpp"
},
"C_Cpp.errorSquiggles": "Enabled",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 100, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false, PointerAlignment: Left}",
"cmake.configureOnOpen": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"autoDocstring.docstringFormat": "google-notypes",
"r.bracketedPaste": true,
"r.plot.useHttpgd": true
"bazel-cpp-tools.compileCommands.targets": ["//..."],
"jupyter.jupyterServerType": "local",
"files.associations": {
"functional": "cpp",
"*.evaluator": "cpp",
"*.traits": "cpp",
"fft": "cpp",
"openglsupport": "cpp",
"regex": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"utility": "cpp",
"hash_map": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"filesystem": "cpp",
"locale": "cpp",
"mprealsupport": "cpp",
"nonlinearoptimization": "cpp",
"dense": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"compare": "cpp",
"concepts": "cpp",
"ios": "cpp",
"queue": "cpp",
"stack": "cpp",
"__functional_base": "cpp",
"alignedvector3": "cpp",
"typeindex": "cpp",
"*.ipp": "cpp",
"*.inc": "cpp",
"core": "cpp",
"geometry": "cpp",
"qtalignedmalloc": "cpp",
"matrixfunctions": "cpp",
"bvh": "cpp"
},
"C_Cpp.errorSquiggles": "Enabled",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 100, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false, PointerAlignment: Left}",
"cmake.configureOnOpen": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"autoDocstring.docstringFormat": "google-notypes",
"r.bracketedPaste": true,
"r.plot.useHttpgd": true,
"python.analysis.extraPaths": ["./outlaw", "./imprint/python"]
}
Empty file.
84 changes: 84 additions & 0 deletions confirm/confirm/lewislib/batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import numpy as np


def pad_arg__(a, axis, n_pad: int):
pad_element = np.take(a, indices=0, axis=axis)
pad_element = np.expand_dims(pad_element, axis=axis)
new_shape = tuple(a.shape[i] if i != axis else n_pad for i in range(a.ndim))
return np.concatenate((a, np.full(new_shape, pad_element)), axis=axis)


def create_batched_args__(args, in_axes, start, end, n_pad=None):
def arg_transform(arg, axis):
return pad_arg__(arg, axis, n_pad) if n_pad is not None else arg

return [
arg_transform(
np.take(arg, indices=range(start, end), axis=axis),
axis,
)
if axis is not None
else arg
for arg, axis in zip(args, in_axes)
]


def batch(f, batch_size: int, in_axes):
def internal(*args):
dims = np.array(
[arg.shape[axis] for arg, axis in zip(args, in_axes) if axis is not None]
)
if len(dims) <= 0:
raise ValueError(
"f must take at least one argument "
"whose corresponding in_axes is not None."
)

dims_all_equal = np.sum(dims != dims[0]) == 0
if not dims_all_equal:
raise ValueError(
"All batched arguments must have the same dimension "
"along their corresopnding in_axes."
)

dim = dims[0]
batch_size_new = min(batch_size, dim)
n_full_batches = dim // batch_size_new
remainder = dim % batch_size_new
n_pad = batch_size_new - remainder
pad_last = remainder > 0
start = 0
end = batch_size_new

for _ in range(n_full_batches):
batched_args = create_batched_args__(
args=args,
in_axes=in_axes,
start=start,
end=end,
)
yield (f(*batched_args), 0)
start += batch_size_new
end += batch_size_new

if pad_last:
batched_args = create_batched_args__(
args=args,
in_axes=in_axes,
start=start,
end=dim,
n_pad=n_pad,
)
yield (f(*batched_args), n_pad)

return internal


def batch_all(f, batch_size: int, in_axes):
f_batch = batch(f, batch_size, in_axes)

def internal(*args):
outs = tuple(out for out in f_batch(*args))
return tuple(out[0] for out in outs), outs[-1][-1]

return internal
23 changes: 23 additions & 0 deletions confirm/confirm/lewislib/grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
import pyimprint.grid as pygrid


def make_cartesian_grid_range(size, lower, upper):
assert lower.shape[0] == upper.shape[0]

# make initial 1d grid
center_grids = (
pygrid.Gridder.make_grid(size, lower[i], upper[i]) for i in range(len(lower))
)

# make a grid of centers
coords = np.meshgrid(*center_grids)
centers = np.concatenate([c.flatten().reshape(-1, 1) for c in coords], axis=1)

# make corresponding radius
radius = np.array(
[pygrid.Gridder.radius(size, lower[i], upper[i]) for i in range(len(lower))]
)
radii = np.full(shape=centers.shape, fill_value=radius)

return centers, radii
Loading