semvec/pypi-packages huggingface dataset:
simple-dictpath 1.0.3
Provides path-like access to nested dictionary elements
Requires Python: >=3.10

# Simple DictPath
Provides a simple path-like access to nested dictionary elements

# Install
```bash
pip install simple-dictpath
```

# Examples
```python
from dictpath import dictp

# First declare a dictp, just like a regular dict.
testval = dictp({
    "first": {
        "second": {
            "animals": [
                {
                    "type": "cat",
                    "name": "meow1",
                    "children": 2
                },
                {
                    "type": "cat",
                    "name": "meow1",
                    "children": 4
                },
                {
                    "type": "cat",
                    "name": "meow1",
                    "children": 6
                },
                {
                    "type": "dog",
                    "name": "dog1",
                    "eye_colour": "blue"
                },
                {
                    "type": "dog",
                    "name": "dog2",
                    "eye_colour": "green"
                },
            ]
        }
    }
})

# dictps can behave just like regular dicts when needed:
# prints: 'meow1'
print(testval["first"]["second"]["animals"][0]["name"])

# But the power comes in cleanly accessing nested elements.
# To use, just call the dictp value like a function with '()' syntax:
animals = testval("first/second/animals")
print(animals)

# If a any key is missing, whole thing just returns None:
cars = testval("first/third/cars")
assert(cars is None)

# To force a keyError, use raise_if_missing:
# This throws: KeyError: 'third'
testval("first/third/cars", raise_if_missing=True)

# You can use list indexes to only get certain elements in a nested list
# prints: 'cat'
first = testval("first/second/animals/0/type")
print(first)

# Uses list comprehension, e.g. "1:2", ":-1", ":", etc.
last_two = testval("first/second/animals/-2:/type")
middle_cats = testval("first/second/animals/1:-2/name")
all_animals = testval("first/second/animals")
all_types = testval("first/second/animals/:/type")

# If key actually is a string with ":", use raw_index option
testval("real/key/:/a", raw_index=True)

# To only get list items that have a specific subkey, use drop_missing:
# This returns [None, None, None, 'blue', 'green']
testval("first/second/animals/:/eye_colour")
# This returns ['blue', 'green']
testval("first/second/animals/:/eye_colour", drop_missing=True)

# You can also set a overide the value if missing:
# This returns ['unknown', 'unknown', 'unknown', 'blue', 'green']
testval("first/second/animals/:/eye_colour", value_if_missing="unknown")

# These both return "no cars"
testval("first/second/cars", value_if_missing="no cars")
testval("first/second/cars/0/type", value_if_missing="no cars")
```
projplot 1.0
Projection plots for assessing convergence of optimization routines

# **projplot**: Utilities for Creating Projection Plots

**projplot** provides a set of tools to assess whether or not an optimization algorithm has converged to a local optimum.  Its main function does this by visualizing the "projection plots" of the objective function `f(x)` -- that is, by plotting `f` against each coordinate of `x` with the other coordinates fixed at the corresponding elements of the candidate optimal solution `x_opt`.  

This package has a similar goal to the R package [**optimCheck**](https://github.com/mlysy/optimCheck).

## Installation

This package is available on [PyPi](https://pypi.org/project/projplot/) and can be installed as follows:

```bash
pip install projplot
```

## Documentation

Available on [Read the Docs](http://projplot.readthedocs.io/).

## Example

An overview of the package functionality is illustrated with the following example. Let `f(x) = x^TAx - 2b^Tx` denote a quadratic objective function in `x`, which is in the d-dimensional real space. If `A` is a positive-definite `d x d` matrix, then the unique minimum of `f(x)` is `x_opt =A^{-1}b`. 

For example, suppose we have

```python
import numpy as np

A = np.array([[3., 2.],
              [2., 7.]])
b = np.array([1., 10.])
```

Then we have that the optimal solution is `x_opt = (-0.765, 1.647)`. Now, **projplot** allows us to complete a visual check. The following information will need to be provided:

* The objective function (`obj_fun`): This can be either a vectorized or non-vectorized function. 
*  Optimal values (`x_opt`): This will be the optimal solution for your function. 
*  Upper and lower bounds for each parameter (`x_lims`): This will provide an initial range of values to observe.
*  Parameter names (`x_names`): These are the names of your parameters, i.e. theta, mu, sigma
*  The number of points to plot for each parameter (`n_pts`): This is the number of points that each parameter will be evaluated at for their respective plot. 

```python
# Optimal values
x_opt = np.array([-0.765,  1.647])

# Upper and lower bounds for each component of x
x_lims = np.array([[-3., 1], [0, 4]])

# Parameter names
x_names = ["x1", "x2"]

# Number of evaluation points per coordinate
n_pts = 10

import projplot as pjp

def obj_fun(x):
    '''Compute x'Ax - 2b'x.'''
    y = np.dot(np.dot(x.T, A), x) - 2 * np.dot(b, x)
    return y

# Obtain plots with vertical x lines
pjp.proj_plot(obj_fun, x_opt=x_opt, x_lims=x_lims,
              x_names=x_names, n_pts=n_pts,
              opt_vlines=True)
```

![alt](docs/images/plot_vlines.png)

### Further Reading

See documentation for [advanced use cases](https://projplot.readthedocs.io/en/latest/example.html#advanced-use-cases) and an [FAQ](https://projplot.readthedocs.io/en/latest/faq.html).