-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
two more simple tests for the matrix action and the resampler
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
import sys | ||
PROJECT_PATH = os.getcwd() | ||
SOURCE_PATH = os.path.join( | ||
PROJECT_PATH,"src" | ||
) | ||
sys.path.append(SOURCE_PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from action.matrix_action import MatrixAction | ||
from torch import zeros, rand | ||
import torch | ||
### Test 1: set fields to zero should return zero action (wit non-zero coeffs) | ||
### Test 2: set coeffs to zero should return zero action (with non-zero fields) | ||
|
||
def test_scalar_matrix_zero_field(): | ||
action_dict = dict(beta=1) | ||
# generate zero-valued fields | ||
cfgs = zeros(100,10,10) # 0 axis is the batch axis ie number of cfgs | ||
result = MatrixAction(**action_dict) | ||
S = result.action(cfgs) | ||
for i in range(100): | ||
assert S[i] == 0 | ||
|
||
def test_scalar_matrix_zero_beta(): | ||
action_dict = dict(beta=0) | ||
# generate zero-valued fields | ||
cfgs = rand(100,10,10) # 0 axis is the batch axis ie number of cfgs | ||
result = MatrixAction(**action_dict) | ||
S = result.action(cfgs) | ||
for i in range(100): | ||
assert S[i] == 0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
from numpy import ones, mean | ||
from random import randint | ||
|
||
from lib.stats.resampler import Resampler | ||
|
||
# all this does is check that if you resample from a set of identical numbers the mean and std of the sample and resample will be exactly equal. | ||
|
||
def test_resampler(): | ||
resampler = Resampler() | ||
sample = randint(1,100)*ones((30)) | ||
sample_mean = mean(sample) | ||
resample_mean, resample_std = resampler.eval(sample) | ||
assert (sample_mean == resample_mean) & (resample_std == 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters