Bardo.Utils (Bardo v0.1.0)

View Source

Utility functions for the Bardo system.

Summary

Functions

Return correct module syntax based on SDK environment configuration.

Seed PRNG for the current process.

Generate a random string of the specified length.

Safely convert binary to Erlang term.

Safely serialize Erlang term to binary.

Saturate a value between a minimum and maximum limit.

Return system metrics.

Checks if vector A dominates vector B with a minimum improvement percentage.

Calculate vector difference with minimum improvement percentage (MIP).

Functions

get_module(module)

@spec get_module(atom()) :: atom()

Return correct module syntax based on SDK environment configuration.

random_seed()

@spec random_seed() :: {map(), any()}

Seed PRNG for the current process.

Uses exs1024s (not cryptographically strong, but fast).

random_string(length)

@spec random_string(non_neg_integer()) :: String.t()

Generate a random string of the specified length.

Parameters

  • length - The length of the random string to generate

Returns

  • A random string of the specified length

safe_binary_to_term(binary)

@spec safe_binary_to_term(binary()) :: {:ok, term()} | no_return()

Safely convert binary to Erlang term.

safe_serialize_erlang(term)

@spec safe_serialize_erlang(term()) :: binary()

Safely serialize Erlang term to binary.

sat(value, limit)

@spec sat(float(), float()) :: float()

Saturate a value between a minimum and maximum limit.

Examples

iex> Bardo.Utils.sat(1.5, 1.0)
1.0

iex> Bardo.Utils.sat(-1.5, 1.0) 
-1.0

iex> Bardo.Utils.sat(0.5, 1.0)
0.5

system_metrics()

@spec system_metrics() :: map()

Return system metrics.

vec1_dominates_vec2(a, b, mip)

@spec vec1_dominates_vec2([float()], [float()], float()) :: boolean()

Checks if vector A dominates vector B with a minimum improvement percentage.

Returns true if all elements in A are significantly better than in B.

vec1_dominates_vec2(list1, list2, mip, acc)

@spec vec1_dominates_vec2([float()], [float()], float(), [float()]) :: [float()]

Calculate vector difference with minimum improvement percentage (MIP).