Current section
Files
Jump to
Current section
Files
src/tastoids@tastoid.erl
-module(tastoids@tastoid).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/tastoids/tastoid.gleam").
-export([from/1, from_taste/2, from_impression/2, from_sparse_embedding/2, from_dense_embedding/1]).
-export_type([tastoid/1, impression/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type tastoid(EGG) :: tasteless |
{tastoid, tastoids@taste:taste(EGG), integer()}.
-type impression() :: yum | yuck | meh | {saw, float()} | pass.
-file("src/tastoids/tastoid.gleam", 28).
?DOC(
" Coerce a `thing` of an into a `Tastoid`, assuming...\n"
"\n"
" - The `thing`'s type is the `Imbedding(space)` of the `Tastoid`\n"
" - The sentiment of that thing is `1.0` ~ a count of its occurances\n"
"\n"
" In effect, `from(thing)` is `1` of that thing, as a `Tastoid`\n"
" \n"
" ## Example:\n"
"\n"
" \"from\" |> tastoid.from -> Tastoid(Taste(\"from\", 1.0\"), k=1) \n"
" 42 |> tastoid.from -> Tastoid(Taste(42, 1.0), k=1)\n"
).
-spec from(tastoids@imbedding:imbedding(EGH)) -> tastoid(tastoids@imbedding:imbedding(EGH)).
from(Index) ->
_pipe = tastoids@taste:from_one(Index),
{tastoid, _pipe, 1}.
-file("src/tastoids/tastoid.gleam", 47).
?DOC(
" A _tasting_ of a taste and the impression thereof (e.g. a 'weight'\n"
" or _value-multiplier_) yield a Tastoid of cardinality (k=1).\n"
).
-spec from_taste(tastoids@taste:taste(EGL), impression()) -> tastoid(EGL).
from_taste(Taste, Impression) ->
case Impression of
yum ->
_pipe = Taste,
{tastoid, _pipe, 1};
yuck ->
_pipe@1 = Taste,
_pipe@2 = tastoids@taste:negate(_pipe@1),
{tastoid, _pipe@2, 1};
meh ->
_pipe@3 = Taste,
_pipe@4 = tastoids@taste:scale(_pipe@3, -0.05),
{tastoid, _pipe@4, 1};
{saw, Worth} ->
_pipe@5 = Taste,
_pipe@6 = tastoids@taste:scale(_pipe@5, Worth),
{tastoid, _pipe@6, 1};
pass ->
tasteless
end.
-file("src/tastoids/tastoid.gleam", 62).
?DOC(
" Given any index (`string`, `Int`, or `Set(index)``), coerce it into\n"
" a simple Tastoid worth a single contribution (k=1)\n"
).
-spec from_impression(EGO, impression()) -> tastoid(EGO).
from_impression(Index, Sentiment) ->
_pipe = tastoids@taste:from_one(Index),
from_taste(_pipe, Sentiment).
-file("src/tastoids/tastoid.gleam", 71).
?DOC(
" Coerce a sparse/dense embeddings pair of value and index lists\n"
" into a conjugated Tastoid worth a single contribution (k=1)\n"
).
-spec from_sparse_embedding(list(float()), list(EGR)) -> tastoid(EGR).
from_sparse_embedding(Values, Indices) ->
_pipe = gleam@list:zip(Indices, Values),
_pipe@1 = tastoids@taste:from_tuples(_pipe),
from_taste(_pipe@1, yum).
-file("src/tastoids/tastoid.gleam", 83).
?DOC(
" Experimental: A (_quiet_) naive dense -> sparse\n"
" mapper to facilitate experimentation\n"
" (see `test/playground/fruit.gleam`)\n"
).
-spec from_dense_embedding(list(float())) -> tastoid(integer()).
from_dense_embedding(Values) ->
_pipe = Values,
_pipe@1 = gleam@list:index_map(_pipe, fun(V, I) -> {I, V} end),
_pipe@2 = tastoids@taste:from_tuples(_pipe@1),
from_taste(_pipe@2, yum).