Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Normalizes the values of an Association
ResourceFunction["AssociationNormalize"][assoc] divides each value in assoc by the Norm of its values. | |
ResourceFunction["AssociationNormalize"][assoc,f] divides each value in assoc by a function f of its values. |
Normalize an Association with three values:
In[1]:= |
Out[1]= |
Normalize an Association with three values so that the values total to 1:
In[2]:= |
Out[2]= |
Symbolic values:
In[3]:= |
Out[3]= |
Use an arbitrary norm function:
In[4]:= |
Out[4]= |
An association with complex values:
In[5]:= |
Out[5]= |
Normalize using exact arithmetic:
In[6]:= |
Out[6]= |
An association where all the values are zero:
In[7]:= |
Out[7]= |
Here is an association in which the keys are various attributes and the values are probabilities (the problem is taken from the Probabilistic Graphical Models book contained in the Sources section). The goal is to figure out the probability that the value of "sat" is "s1" given that the grade is "s2":
In[8]:= |
Eliminate any associations in which the value of "grade" is not "g2":
In[9]:= |
Out[9]= |
Normalize the remaining probabilities:
In[10]:= |
Out[10]= |
Use KeySelect to compute the probability that the "sat" value is "s1":
In[11]:= |
Out[11]= |
Delayed values are evaluated:
In[12]:= |
Out[12]= |
In[13]:= |
Out[13]= |
This work is licensed under a Creative Commons Attribution 4.0 International License