make chroma refinements for v1.3.0

This commit is contained in:
smgr 2025-11-12 23:54:52 -08:00
parent 9c312943de
commit a875817fd0
10 changed files with 1660 additions and 12 deletions

68
examples/class.py Normal file
View File

@ -0,0 +1,68 @@
class WLBPosteriorEstimator(PosteriorEstimatorTrainer):
"""
Weighted likelihood bootstrap (WLB) estimator.
Trains models to approximate draws from the *weight posterior* (under
Jeffrey's prior).
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
assert not self.use_non_atomic_loss
def get_dataloaders(
self,
starting_round: int = 0,
training_batch_size: int = 200,
validation_fraction: float = 0.1,
resume_training: bool = False,
dataloader_kwargs: dict | None = None,
) -> tuple[data.DataLoader, data.DataLoader]:
"""
Add logic for generating session-specific WLB weights.
This is probably the easiest place to stick some fixed weights on a
point-wise basis for a given training run, and we load them later where
we need them in the ``train()`` loop.
"""
theta, x, prior_masks = self.get_simulations(starting_round)
# generate session specific WLB weights to attach point-wise
N = theta.shape[0]
wlb_z = Exponential(1.0).sample((N,))
wlb_w = (wlb_z / wlb_z.sum()) * N
dataset = data.TensorDataset(theta, x, prior_masks, wlb_w)
num_examples = theta.size(0)
num_training_examples = int((1 - validation_fraction) * num_examples)
num_validation_examples = num_examples - num_training_examples
if not resume_training:
permuted_indices = torch.randperm(num_examples)
self.train_indices, self.val_indices = (
permuted_indices[:num_training_examples],
permuted_indices[num_training_examples:],
)
train_loader_kwargs = {
"batch_size": min(training_batch_size, num_training_examples),
"drop_last": True,
"sampler": SubsetRandomSampler(self.train_indices.tolist()),
}
val_loader_kwargs = {
"batch_size": min(training_batch_size, num_validation_examples),
"shuffle": False,
"drop_last": True,
"sampler": SubsetRandomSampler(self.val_indices.tolist()),
}
if dataloader_kwargs is not None:
train_loader_kwargs = dict(train_loader_kwargs, **dataloader_kwargs)
val_loader_kwargs = dict(val_loader_kwargs, **dataloader_kwargs)
train_loader = data.DataLoader(dataset, **train_loader_kwargs)
val_loader = data.DataLoader(dataset, **val_loader_kwargs)
return train_loader, val_loader

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

17
scripts/render.sh Normal file → Executable file
View File

@ -4,12 +4,14 @@
set -euo pipefail set -euo pipefail
w=${1:?width}; h=${2:?height} w=${1:?width}; h=${2:?height}
out="kitty-$(date +%Y%m%d-%H%M%S).png" out=${3:?file};
shift 2 || true #out="kitty-$(date +%Y%m%d-%H%M%S).png"
shift 3 || true
# spawn a kitty window w/ a mark # spawn a kitty window w/ a mark
title="kitty-$(date +%s%N)" title="kitty-$(date +%s%N)"
kitty --title "$title" "$@" & sock="$XDG_RUNTIME_DIR/kitty-$title.sock"
kitty -o allow_remote_control=yes --listen-on "unix:$sock" --title "$title" "$@" &
# create a targeted rule for the marked window and resize # create a targeted rule for the marked window and resize
sleep 2 sleep 2
@ -24,12 +26,15 @@ read gx gy _ < <(awk -F'[ ,x]' '{print $1,$2}' <<<"$geom")
read wx wy ww wh < <(awk -F'[ ,x]' '{print $1,$2,$3,$4}' <<<"$wgeom") read wx wy ww wh < <(awk -F'[ ,x]' '{print $1,$2,$3,$4}' <<<"$wgeom")
inner_geom="$((gx+wx)),$((gy+wy)) ${ww}x${wh}" inner_geom="$((gx+wx)),$((gy+wy)) ${ww}x${wh}"
echo title=$title echo "+ title=$title"
echo geom=$geom echo "+ geom=$geom"
echo out=$out echo "+ out=$out"
# take a screenshot # take a screenshot
mkdir -p "$(dirname "$out")" mkdir -p "$(dirname "$out")"
grim -g "$inner_geom" "$out" grim -g "$inner_geom" "$out"
echo "saved: $out" echo "saved: $out"
# close the kitty window
kitty @ --to "unix:$sock" close-window

27
scripts/screens.sh Normal file → Executable file
View File

@ -1,18 +1,33 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# usage: screens.sh prefix
set -euo pipefail set -euo pipefail
prefix=${1:-}
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
render_script="$script_dir/render.sh" render_script="$script_dir/render.sh"
biomes=(alpine badlands chaparral savanna grassland tundra) #biomes=(alpine)
modes=(light dark) #modes=(light dark)
biomes=(alpine)
modes=(dark)
for biome in "${biomes[@]}"; do for biome in "${biomes[@]}"; do
for mode in "${modes[@]}"; do for mode in "${modes[@]}"; do
symconf config -m "$mode" -s "default-$biome-monobiome" echo "Applying $biome-$mode theme"
sleep 5 symconf config \
"$render_script" 800 600 nvim \ -a kitty,nvim \
-m "$mode" \
-s "default-$biome-monobiome" \
-T font=Berkeley
sleep 2
echo "Taking screenshot..."
"$render_script" 800 600 "images/render/$prefix-$biome-$mode.png" nvim \
+':highlight Cursor blend=100' \ +':highlight Cursor blend=100' \
+':set guicursor=n:block-Cursor' \ +':set guicursor=n:block-Cursor' \
+':silent! setlocal nonumber nocursorline signcolumn=no foldcolumn=no' \ +':silent! setlocal nonumber nocursorline signcolumn=no foldcolumn=no' \
examples/runner.py +':lua vim.diagnostic.config({virtual_text=false,signs=false,underline=false})' \
examples/class.py
done
done