Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a generative method?

I'm familiar with Python generators, however I've just come across the term "generative method" which I am not familiar with and cannot find a satisfactory definition.

To put it in context, I found the term in SQLAlchemy's narrative documentation:

Full control of the “autocommit” behavior is available using the generative Connection.execution_options() method provided on Connection, Engine, Executable, using the “autocommit” flag which will turn on or off the autocommit for the selected scope.

What is a generative method? Trying to iterate the object returned by Connection.execution_options() doesn't work so I'm figuring it's something other than a standard generator.

like image 644
Matty Avatar asked Apr 05 '12 02:04

Matty


People also ask

What is an example of generative?

An example of a generative model might be one that is trained on collections of images from the real world in order to generate similar images. The model might take observations from a 200GB set of images and reduce them into 100MB of weights. Weights can be thought of as reinforced neural connections.

What is a generative approach?

The generative approach is the most frequently used template-based approach. Here, the model is basically the prototypical image patch, usually the template itself. The localization of the object in subsequent frames is obtained by matching the model to candidate positions in the frames.

What is generative machine learning?

Generative modeling is an unsupervised learning task in machine learning that involves automatically discovering and learning the regularities or patterns in input data in such a way that the model can be used to generate or output new examples that plausibly could have been drawn from the original dataset.

Why is a generative model called generative?

A generative model is so called because it tries to learn the probability distribution that generated the data. For example, the Gaussian mixture model will try to learn the parameters of the Gaussian mixture that best fits the data.


2 Answers

It doesn't appear to be a common database concept, but SQLAlchemy uses the term generative in the sense "generated by your program iteratively at runtime". (So, no connection to python generators). An example from the tutorial:

The Query object is fully generative, meaning that most method calls return a new Query object upon which further criteria may be added. For example, to query for users named “ed” with a full name of “Ed Jones”, you can call filter() twice, which joins criteria using AND:

>>> for user in session.query(User).\
...   filter(User.name=='ed').\
...   filter(User.fullname=='Ed Jones'):
...     print user

This call syntax is more commonly known as "method chaining", and the design that allows it as a "fluent interface".

So, in the case of Connection.execution_options(), "generative" means that it returns the modified connection object, so that you can chain the calls as above.

like image 61
alexis Avatar answered Sep 20 '22 06:09

alexis


Looking at the source code of Connection.execution_options (lib/sqlalchemy/engine/base.py), all that method does is add options to the connection.

The idea is that those options influence the future behaviour of e.g. queries.

As an example:

        result = connection.execution_options(stream_results=True).\
                            execute(stmt)

Here, the behaviour was changed in the middle of the connection for just this query. In a way, it "generates" or clones itself as an object that has a slightly different behaviour.

Here you can also set autocommit to True. Example

# obtain a connection
connection = ...
# do some stuff
# for the next section we want autocommit on
autocommitting_connection = connection.execution_options(autocommit=True)
autocommitting_connection.execute(some_insert)
result = autocommitting_connection.execute(some_query)
# done with this section. Continue using connection (no autocommit)

This is what is meant with that section of the documentation. "generative method" refers to a method that returns a modified copy of the same instance that you can continue working with. This is applicable to the classes Connection, Engine, Executable.

like image 21
j13r Avatar answered Sep 20 '22 06:09

j13r