Tuesday, February 1, 2022

Precursor to NFTs

In January of 2014, I tweeted some digital images that I had designed that one could easily say were a precursor to Non-Fungible Tokens, which are all the rage today. I was trying to design content that could not be forged.

I came up with names like the "ALEXCOIN", because I had been studying the rise of Bitcoin and the Blockchain for many years and believed that I could create art that was not capable of being forged, using blockchain technology. I didn't have the technical skill to actually make what would today be called NFTs, so I did it my way via Twitter.

Another name I used was the "ANTIFACECOIN". The concept of "Antiface" and the "Antiface Strategy" are things that I had been working on for over a decade at the time. The idea was really to create art that could not be forged, art where I could be the only possible creator. At the time, I thought that I had succeeded with these little images. This one, in particular, was an actual painting done in acrylic. The others are digital designs meant to be self-portraits. That was one of the aspects of my concept, that these "Coins" were also self-portraits, or self-referring in a sense.

Here in the following tweet, I am calling them "AntifaceCards". I saw them as collectibles. I was really ahead of my time!

Here is proof, in any case, that I was working on the concept of NFT or Non-Fungible Token as early as January, 2014. I don't know if the term NFT even existed then. But certainly I was thinking at the time of the idea of art that could not be forged, using a technological support or backbone such as the Blockchain.

NB: It turns out that I beat the first NFT by several months, the first NFT being created in May, 2014, and mine being created in January, 2014.

"The first known "NFT", Quantum, was created by Kevin McCoy and Anil Dash in May 2014, consisting of a video clip made by McCoy's wife Jennifer. McCoy registered the video on the Namecoin blockchain and sold it to Dash for $4, during a live presentation for the Seven on Seven conference at the New Museum in New York City. McCoy and Dash referred to the technology as "monetized graphics". A non-fungible, tradable blockchain marker was explicitly linked to a work of art, via on-chain metadata (enabled by Namecoin). This is in contrast to the multi-unit, fungible, metadata-less "colored coins" of other blockchains and Counterparty." - Non-fungible token - Wikipedia

Friday, February 19, 2021

Morphological Transformations

I started playing around with the OpenCV library in Python ("cv2"). Here are some of the mathematical morphological operations that can be done on an image of your choosing:

Here is an example of an "erosion" operation done on an image of a gradient. First, here is the input image that I used, of a gradient I also generated programmatically via Python:

And here is the processed image, using the erosion operation with a 3 x 3 kernel of 1s:

As I said, I've been playing around with these mathematical morphological operations, of erosion, dilation, edge detection and sharpening of images, all using the OpenCV library. The functions are pretty simple to use. The library is really powerful, giving you everything you need at the touch of a simple function. One can also use function composition to use a function on top of a function. I wrote some helper functions to facilitate the task of using the morphological transformation functions.

Monday, February 15, 2021

Generating a Gradient Programmatically

I've posted many times on this blog, my experiments in image generation through Python. I've been working on what I call my "Noisefield" project, where I generated a bitmap with random black and white pixels. I have now done something similar, except this time I generated a black to white gradient, using the PIL library in Python.

The idea is pretty simple. You create a vector or array of values from 0 to 255, then you repeat that 256 times, to make a square matrix, or bitmap (because Python puts in the pixels from top-left downwards and towards the right, line by line). So that way you get a gradient. I took the "LINE" variable that I created with a for loop and range() function and then multiplied it by 256 in a variable called MATRIX. I then used an iterator function on the Matrix which I called in the image-generation function by calling next(MATRIX). The result is a smooth matrix.

ADDENDUM: I have found a simpler way of generating a black to white gradient, using the np.linspace function in Numpy.

FOR YOUR INFORMATION: I have written a few blog posts in the past about generating bitmaps with random black and white pixel values, or grey values between 0 and 255. I found a much quicker way to do this using the OpenCV library (cv2). (In passing, this np.random.randint() function gives the same results as the uniform_noise function below, in the second Gist below:

Here's another way to generate noise, Gaussian noise in this case, via OpenCV (cv2). The Gaussian distribution is "smoother" in appearance, as it has mean 128 and standard deviation 20:

With mean 0 and standard deviation 256, we get a "coarser" noise distribution:

As stated, the uniform_noise "randu" function gives the same result as the previous np.random.randint() function, a uniform noise distribution:

If I add the following, "ret,thresh1 = cv2.threshold(uniform_noise,64,255,cv2.THRESH_BINARY)" and then write "cv2.imwrite("Noise.jpg",thresh1)", I get a noisy distribution with many more whites, because of the threshold value being at 64. For every pixel, the same threshold value is applied. If the pixel value is smaller than the threshold, it is set to 0, otherwise it is set to a maximum value, in this case 255, which is pure white. This way it is possible to adjust the parseness if you will of the noisy distribution using the threshold function:

The opposite would be true if we set the treshold higher, to say 250. Then it's mostly black, or at a pixel value of 0:

Friday, February 12, 2021

Finding The Mean Part II

A short while ago, I wrote a blog post called "Finding The Mean" where I gave code of a function I wrote which generates an array of n random real numbers between 0 and 1 inclusively. I wrote the function in Python, in R, and in GNU Octave. My goal was to write the function in as many programming languages as possible. I have now written a version in C.

I will be trying to write the same function in various other programming languages, probably including Ruby, Javascript, Scala, and many others, potentially in some functional programming languages like Haskell or SML (Standard ML). Stay tuned!

In passing, the main idea behind this program is the fact that as an array or list of random real numbers between 0 and 1 grows in size, the average will technically converge on 0.50. It's just a mathematical fact. I think it's called the Law of Large Numbers. "According to the law, the average of the results obtained from a large number of trials should be close to the expected value and will tend to become closer to the expected value as more trials are performed."

Here is a mathematical representation of the Law of Large Numbers:

ADDENDUM: Here is some Scala code that does the same thing, but only seems to work in the REPL. I'm not familiar enough with writing actual scala programs, but as I said it works in the REPL. Just change the value of n.

I was also able to translate the code into Ruby. This works in the REPL and worked as a simple Ruby program, though I think it lacks some of the usual formalism of Ruby programs. I tried to turn it into a function (via function definition) but it said there was an "undefined method", not recognizing the .sum method for arrays. But I got it to work in the following way, decomposed into different lines of code. You just have to change the value of n. Remember, this is all to prove the Law of Large Numbers:

The idea behind this proof of the Law of Large Numbers is simply that given an array of random real numbers (floats) between 0 and 1, the larger the length n of the array, the closer the mean of the values of the array will become to 0.50. That is, the mean of a large number of such random numbers, or the expected value, is 0.50. And if you try these functions with 10,000 or more values in the array, you'll see that it converges on 0.50. This is my so-called "proof" of the Law of Large Numbers.

Monday, July 13, 2020

Pixelating an image

I was thinking of ways of pixelating an image, using simple Python functions. I started with an image of white noise and ran the pixelation function.


The trick I found is simple. You resize the image to a much smaller size, then resize it back to the original size. We can see this in the code. Below are the actual images, the one used as input and the one that came out as output.

"Image.NEAREST" is key here. It's nearest neighbor interpolation that is being used when you resize back up to the original size.

NOISEFIELD_200.png

As always, we start with Gaussian white noise. Then we use the basic image processing functions and get the following.

Pixelated image, result.png


I'm trying to build an app that can generate noise images and then use different functions to "modulate the noise field" as I like to call it. Pixelation is one of the basic image processing functions that I want to have in my future app.


A.G. (c) 2020. All Rights Reserved.



Thursday, April 23, 2020

Finding The Mean

If you perform a series of coin tosses of a fair coin, over a large number of trials, you expect the average of heads and tails to be around 50/50. What I did here below is generate an array, a list, of random numbers, real numbers, between 0 and 1. Then I find the mean of the values of the array. What you see is me taking the sum of a list in Python, itself generated through a list comprehension using the random module to choose random values (float numbers). The idea is to generate numbers between 0 and 1 randomly and average them to test the law of large numbers. I want to end up with a value that is close to the expected value you get from a large number of trials. In my mind, and I'm not a mathematician, I think this is a Gaussian distribution. I'm a big fan of all things related to noise and this experiment makes me think of Gaussian white noise, as a distribution in whatever dimensions.




I'm not a Python expert, but this is the quickest way I could find to get the mean of the array of size n of random values that I wanted. I tried other ways before, but when I refactored it, I got into a functional style of programming and wrote it as a mathematical function. That's why I used a lambda function, because it's an anonymous function, as far as I can tell. Again, I'm not an expert in theoretical computer science either. I just know I used the timeit module and found this function to be relatively quick. I tried the statistics module in Python 3.8 and it was super slow.

I tried doing everything in Numpy, but it was slower than when I used builtin functions like sum. Instead of importing mean functions from different modules, it was better just to sum the array of size n and divide by n to get the mean or expected value. Basically, I create an array of size n of what are essentially probabilities, real numbers, float numbers in Python, between 0 and 1. Then I run many trials, like say 1 million, and get the mean (average value) and it is usually 0.50 or else 0.4999.

I was really wondering about code optimization in Python. As I said, I'm not an expert in Python or in theoretical computer science, and I'm certainly not a mathematician. I just needed a way to come up with a large number of probabilities in a list (an array, a one-dimensional vector). I found I could do this easily with a list comprehension, i.e. [random.random() for i in range(n)], in Python, using the random module. I tried different ways of calculating those random probabilities. My thesis was proved, though. The mean after a million trials is 0.50 or 0.4999 or else 0.5001. Anyway it turns out that one should try to use builtin functions when possible, because they are usually faster. It's like writing the function in C, almost. There is no interpretation, is what I understood from my quick overview of the subject.

I was starting to look into the internals of Python to try to see why builtin functions would be faster. This is the best summary I could find so far:

Use Built-in Data Types
This one is pretty obvious. Built-in data types are very fast, especially in comparison to our custom types like trees or linked lists. That’s mainly because the built-ins are implemented in C, which we can’t really match in speed when coding in Python. - Making Python Programs Blazingly Fast

Addendum:
"A simple rule of thumb (but one you must back up using profiling!) is that more lines of bytecode will execute more slowly than fewer equivalent lines of bytecode that use built-in functions." - p.55, High Performance Python: Practical Performant Programming for Humans by Ian Ozsvald and Micha Gorelick
                                                                         * * *
I did a little more research. After looking into profiling and code optimization, I got to thinking of implementing my function in othe programming languages, with the idea that maybe it would be faster in Fortran or C or whatnot. I'm mostly just familiar with Python, but I was able to write the function, in what I think is working code, in both the R language and in GNU Octave:


The file is named avg_probs.m with my function in GNU Octave code. Here it is in the R programming language.

Those were a few of the other languages that I was able to "translate" my function into, my "average of probabilities" function, as I am calling it now, or avg_probs().

Thursday, September 27, 2018

Refcards: The Beginnings of an Interface

- The latest development in the evolution of the Refcards-System is the creation of a primitive interface;
- Now I can add records to my SQLite3 database through an interface;
- The interface has a button called "Add entry" which upon clicking adds the text ("gets" it) from the Entry and Text widgets in the interface and adds them ("INSERTs" them) directly into the database;
- I've been using Tkinter to create the interface ("frontend") and SQLite3 in Python for the database ("backend");


Wednesday, September 26, 2018

Tkinter Text Widgets in Python

- I have been working hard on my Refcards-System idea, in Python;
- I want it to be a simple database with simple interface where you can add records to a given table and then view your "notes" or "Refcards";
- The idea is to have a GUI to flip through Refcards in the database;


Thursday, June 21, 2018

The Refcards-System Redux

18:52 2018-06-21

- As you may know, I have been working on my "Refcards-System" for years now. I haven't made much progress, but I still have made some progress;
- This latest iteration is all about "writing" to a .csv file; the idea is that a .csv file can be "imported" into a relational database or else opened up as an "Excel" file, making it rather interoperable;

- So what we have is simple. First I create the "filename" using some magical "time" module tricks. I want the filename to basically be the current timestamp, + the .csv file ending;
- Then basically I create the first "row" which are the "fieldnames" in the .csv file, and then I write the second "row" which is my content;
- Notice that I am using "raw_input", in Python that allows me to enter text directly into the file, with a prompt;
- The point is really to have content in .csv format, which is portable, interoperable, and lightweight as well. It's also a format that has withstood the test of time.

Sunday, March 11, 2018

Idiomatic Random Thoughts

I've been practicing my Python again. I am working on a Python version of an old boardgame called Stock Ticker. I had a breakthrough after thinking about it for 2 years. Right now, though, I'm just goofing off. This is imaginary code for the use of a random_thoughts module.


I've been watching videos of Python masters teaching their great wisdom. Of note is the work of Raymond Hettinger. I've learned a lot from watching him talk about writing beautiful Python code. I am only 7 years or so into my Python practice, so I'm not yet an expert. I am entering into the "intermediary" territory, though, because I can read almost any Python code and pretty much know what it's doing, and I can write code to solve problems I encounter every day. I still can't write a packaged app, a full-blown executable, with interface and everything. But I am beginning to truly understand Python, which is still a big accomplishment for me.

My dream is to think Pythonic thoughts. I want to turn my thoughts into mathematical expressions, and be able to execute them using Python as a programming language. Hence the thought experiment on the random_thoughts module. It's not really good Python code, but it's a start. The idea is that there would be a function I could use to turn my thoughts directly into idiomatic Python.

Friday, March 31, 2017

Modulations, Modulations, Modulations

Here is yet another experiment in generating noisy images. This time the pattern is obvious, regular. The point of all this is to start with noise and modulate the noise until I get something "visually interesting." Below the code I wrote to generate the image is the resultant image itself.


Noise field by A.G. (c) 2017. All Rights Reserved.

Monday, March 27, 2017

Code Reading

I just wanted to say that when I'm in the coding mood/mode, I like to do an insanely large amount of code reading. I go on Github or look at Github Gists, or look at code on-line in tutorials and quickstarts. It's really what helps me the most in learning to code in Python, which I've been doing for a good 6 years now.

There's a whole other side to what I just said that I won't go into too many details about. Suffice to say that I believe in a kind of New Documentation where the purpose of documenting code is precisely for the ambient code-reader who happens to stumble across the code doing searches on the web or on Github.

Think of it this way. If you're writing code that's going to be read by yourself or your team members, you can get away with documenting less or maybe not even at all. But in the open source universe, you have to think of an indeterminate number of people who might read your code 5 or 10 or 50 or 100 years later. So it's important I think to be very "literate" in one's documentation.

You can never take for granted that future code-readers are going to know what you were trying to do, even if they can get your code to work. One thing I learned is that you have to UNDERSTAND the code, how and why it works, along with what it's purpose is. I can write a Python script that does exactly what I needed it to do and yet not fully understand it because I'm just basing my coding on idioms I learned and stuff I saw other coders write in my code-reading experience.

It's tantamount to saying something and not truly understanding it. You can still get the point across to an audience, but what's the point if you don't even fully understand what you are saying? A wise man once told me to only ever speak about what I have knowledge of. I think it should be the same thing with code. Use restraint. Only write code about what you understand and have knowledge of.

I find code-reading a great passtime. I can almost never get the code to run on my machine, but I see how the problem was solved, or at least one possible avenue. Often I find the code very ugly and hard to read, and that's when I go back to the basics and make sure I know what I'm doing when I write code.

I think that a certain responsibility comes from being able to code, just as one has the responsibility to watch what one says when one is speaking. Think before you open your mouth, or before you code something.

Procedural texture synthesis it is called

Procedural texture synthesis by A.G. (c) 2017. All Rights Reserved.


...

Sunday, March 26, 2017

Noise Field Breakthrough

Procedural texture synthesis. A.G. (c) 2017. All Rights Reserved.
I had a mild breakthrough. The above image was generated entirely through numerical computation. I essentially created a vector with 65536 values, all either a 0 or 255. I generated various segments of all black or all white, of different lengths, and I created the 65536 vector by randomly choosing between various length "LINES" or line segments.

Then I generated a Gaussian distribution matrix and did a matrix operation equivalent to a difference blend mode. That is, I took my two separate 65536 vectors and turned them into np.array types, did the arithmetic, subtracting one from the other, and then I ended up with the above image.

There must be easier ways to do this, but I chose to work with a vector of 65536 values. I just am learning to construct it in different ways. I will try to do it using list comprehensions and functional programming, to make the job more elegant.

I repeat: The above image was generated entirely through numerical computation in a step by step, therefore algorithmic, method. I just did some of it manually, creating the 65536 vectors.

Saturday, March 25, 2017

Noise Field Redux

This time I am "seeding" an image with random black and white pixels.


I used the "L" mode, which is a standard mode for an image that has 8-bit pixels, black and white. I am choosing a black or white pixel at random with the random module:

im.putpixel((x, y), random.choice([0,255]))

The next step is to write modulation functions to modulate the noise field. I am working on a threshold function for when I make noise that is in grayscale. I am also trying to work out a pixelate function, which is proving more difficult than I thought.

The bit at the end with the saving of the image may look weird, but it allows me to save the image with its date and time as filename. For now, this makes it easier for me to work with my images. Here is an image made with the code above.

Noise field generated with Python code. A.G. (c) 2017. All Rights Reserved.

Monday, August 8, 2016

Noise Fields, Noise Fields, Noise Fields

Noise Field (512 px x 512 px). An applied noise function. A.G. (c) 2016.

Here we have pretty much the same thing as before, i.e. a function called noisefield() that returns an image. This time what we did, or tried to do, was to generate a "LINE" first that is a list of 512 "RGB tuples" which in this case, as before, are randomly generated (via the noxel() function).

Then, simply enough, all we did was create an entity called "MATRIX" that is made up of 512 "LINEs". We used an "iter" function to create an object called "nixel", as you can see, that iterates over the "MATRIX" object which is basically just a very long sequence of RGB tuples made up of the concatenation of 512 "LINEs"

What you can see in the image above, created via this Python script, is an interesting series of LINEs, each with randomly chosen RGB tuple values.

Here is the code, hosted on Github as a Github Gist.

You might as well ask, since I know you're thinking it: Why go through all the troube? Couldn't you do this much more simply with less code and in a much more idiomatic style, plus much more elegantly? The answer is, yes, of course I could. This is only the beginning. I have structured the code this way because I want to be able to create what I call "mod" functions which are "modulations of the noise field", so to speak. I want to be able to create noise fields and then apply functions to them, either on a pixel-by-pixel basis or else on the whole image, or else on individual "LINEs" which in this case, as vectors if you will of random "RGB tuples", the LINEs that is, are actually "column" vectors and not "row" vectors, if you will. That is to say, the LINEs in the Image, of individual random RGB tuples, appear "horizontally", but the actual LINE in the code ends up being in the "vertical" direction. This is not a glitch, it's because in the code in the 5th line of the noisefield() function, we have (x,y), i.e.

im.putpixel((x, y), nixel.next())

We could just as easily make the uniform-colored lines appear on the vertical axis in the final image just by switching (x,y) to (y,x). To be continued...

Saturday, August 6, 2016

Prolegomenon to Noise Field Theory (via Signal Science)

Noise Field (512 px x 512 px). An applied noise function. A.G. (c) 2016.

Noise Field Theory is a somewhat complex domain that I have been investigating, exploring, now for many years. For now, I just want to share some actual working code in order to eventually develop the theory of Noise Fields in a way that people can actually understand. That way me critics can finally realize that I'm not so crazy after all.

Simply put, you have these "fields" called noise fields. The simplest way to imagine a noise field is to just think of a matrix of numbers, but not just any old matrix. Imagine a digital image, a Bitmap, say, that is 256 pixels by 256 pixels. The simplest form of a noise field is just such an image/matrix made up of random values.

As you shall see in the code, I create something called a "noxel" which is meant to be a kind of "pixel", i.e. a "noise pixel" = "noxel". In RGB, it has three values, each of which is a random number between 0 and 255, the possible values for an image inside the RGB model.

What we do is create an image and assign a new noxel to each pixel, creating essentially a random matrix, a.k.a. a noise field. What I will do a little later is explain what this all means, because I can assure you, there is a much deeper meaning that is not obvious at first. (It took me 20 years to get this far, this is not simple, yet it is quite elegant).

That's it for now. Stay tuned for more details on the noise field as data model - for we are using Python programming to explore Noise Field Theory. It becomes a language, if you will, to speak about noise fields. I will also show why Noise Field Theory is not only best explained through Python itself, but through what we have called Signal Science. In the above case in point, in the code, the "noxel" function is "passed" as an "input" into the "noisefield" function. This allows us to tackle the also complex subject of Signal Science, which essentially is a purely signal-based view of the world and everything in it. To be continued...

Wednesday, June 29, 2016

Pythonic Wrapper for Wikipedia API Redux

I mentioned a Pythonic wrapper for the Wikipedia API in a post on this blog a while back, about the so-called "Refcards-Project". Here I want to just "reflect" on this Wikipedia library/module for a few moments.

As stated before, it is easy enough to install, just type:

$ pip install wikipedia
So let's do something really simple. Let's take a Wikipedia page and extract a list of all the links found in that page (Links to Wikipedia pages, i.e. a list of the "titles" of the Wikipedia pages linked to WITHIN the given Wikipedia page we start with). It could go something like this:

>>> import wikipedia
>>> refcard = wikipedia.page("Reference card")
>>> refcard_links = refcard.links
>>> type(refcard_links)
<type 'list'>
>>> len(refcard_links)
18
>>> for i in refcard_links:
print i
Application program
Card stock
Cheat sheet
Computer platform
Data mining
Formal language
HTML
Idiom
Index card
LaTeX
Markup language
Memory
PDF
Printing
Programming language
R (programming language)
Syntax
User guide
That's it for now. I want to leave it at this as far as Python code goes, but as I said I want to "reflect" on this. I want to reflect on it in two fundamental ways. One way to reflect on Python code is to do it "philosophically" if you will. That's one form of reflection/introspection. You just "think" about it. The other way, though, is via the interpreter.

If you go back, you will see that I "asked" IDLE this question:


>>> type(refcard_links)
And what did it say, what was the answer?

>>> type(refcard_links)
<type 'list'>

Okay. So here's the point: I think it's important to "interrogate" the data that you are working with. It's important to know what the "types" of things are, and also many other "questions" can be asked. If you noticed, I also "asked" what the "length" of the list was:

>>> len(refcard_links)
18

Now, I'm not a computer scientist. I'm just an artist and researcher, a philosopher if you will. So for me "Reflection" just means "asking questions about something". You see, I "expected" that refcard_links would be of type list, but I had to make sure. I also wanted to know what the length was just in case it contained 13,000 different items. That would screw things up if I were writing a kind of web crawler that crawled every Wikipedia "page" in such a list of Wikipedia hyperlinks. Since there were only 18 items in the list (the "associative array") then I knew I was in business.

So what I could do, if I wanted, is write a simple script that takes any given Wikipedia page, given that it exists, and makes a list of say the first 5 links to other Wikipedia pages within that article. Then it could take say the first 2 links, and get/fetch those pages, and make lists of the first 5 links to THOSE pages, and so on and so forth.

I'm not trying to build a Wikipedia crawler, though. I'm actually much more interested in using Wikipedia to do things closer to what we might call Natural Language Processing. That is, as an author of fiction, I'd like to use content on Wikipedia to generate "cut-up novels", let's say, in the style of one William S. Burroughs.

Say I want to build a so-called "cut-up engine". I need text to "seed" the engine. So I take a bunch of pseudo-random Wikipedia pages, or Wikipedia pages that are "interlinked", and I fetch the content and then I can start building Markov chains or whatnot, using the content and other methods to generate new, creative texts algorithmically.

The possibilities are endless. Once you have a "source" of textual content, there are no limits to what you can do. I could build a conversational agent that uses Wikipedia content. Say someone says something... I can quickly scan the textual data of what they said, then find keywords, or try, then look them up.. then I can have a dozen Wikipedia pages about the different "objects" or events or people or places WITHIN THE TEXT I am analyzing.

Granted, I will need much more complex "machinery" under the hood, but to me this simple Wikipedia library/module already offers me a vast FIELD OF OPPORTUNITIES for testing my Pythonic skills. That's all for now. Just a reflection on how to simply get something going, how to start thinking about the possibilities of what can be built with just a quick "skim" over the basics of a given Python library or module. The rest is just up to two t hings: a) how much work you're willing to put into it, including further research and so forth and b) how fertile your imagination is, or how creative you are. The rest is just details.

I could also do simple data analysis. I could want to see how many pages link back to some given page. I could make graphs or networks of hyperlinks between Wikipedia pages. I could do visualizations. Hey look, this many pages link back to the "Philosophy" page. The links that appear in the first paragraph on any given Wikipedia page seem to have this or that property or attribute or characteristic. That's all data science is, data analysis. You need to start SOMEWHERE, though. And as an amateur/beginner in Python, I want to make things as fun as possible. So I explore libraries and modules like this to see what is the SIMPLEST thing I could build to do something INTERESTING.


Sunday, June 12, 2016

[FIELDS_MEDALISTS]

On the Wikipedia page for the "Fields Medal", there is a table of Fields Medalists who were awarded the very high honor in the field of Mathematics. For fun, I took the data from this table and started playing around with the content in the "citation" column.

That is to say, in the table on the Fields Medal Wikipedia page, one has "fields" of "metadata" if you will, for Year, ISM Location, Medalists, Affiliation (when awarded), Affiliation (current/last), and one for Citation. An example of one of the "records" in the table is (in a form of comma-separated values styled representation):

1936, "Oslo, Norway", "Lars Ahlfors", "University of Helsinki, Finland", "Harvard University, US", "Awarded medal for research on covering surfaces related to Riemann surfaces of inverse functions of entire and meromorphic functions. Opened up new fields of analysis."

What I wanted to do, in Python, was make a "list" ("associative array") of all of the data from the table. I would then play with random selections of given "citation" data in the table.

I did this and I had a lot of fun. Without going into too many details, let's say that I created a list with just the citations, if that's all I want. I would make a statement starting with:

FIELDS_MEDALISTS = [...]

...with a "nested list" of the citations, within the FIELDS_MEDALISTS list, or whatever I want to call it, i.e. "CITATIONS", etc.

Once I had access to the citation data, the text or content of them, if you will, I thought that I could randomly choose citations. Ideally, I'd like to be able to do something slightly more sophisticated with the text of the citations, like make a word cloud of the words, minus stop-words, that are most common.

I think that you can see where I am trying to go with this: CREATE A RANDOM FIELDS MEDALIST CITATION (probably using markov chains, not sure yet). The idea, then, would be to write a kind of "FIELDS MEDALIST PREDICTOR".. that optimally would be ablt o predict future winners of the award. Although, honestly, I doubt I can do a very good job, since I'm not yet all that masterful when it comes to machine learnig and so forth. But the dataset itself, the "table" I called it, is pretty small. There haven't been all that many Fields Medalists in human history.

[more to come]...

Tuesday, April 5, 2016

Introduction To The Refcards Project

Hi, all. I've been semi-secretly working on a project that I internally am calling The Refcards Project. It has gone by mamy names, and in any case for now let's just call it that.

So here it is. I am doing many things as a burgeoning young programmer, and here is some of that. First of all, I'm working on what I am calling "Internals". In Python, since everything I do in Python, "internals" just means the stuff that happens "internally", like at the level of compilation, at the level of the interpreter and so forth. I'm only interested in the stuff that happens "under the hood" when you actually "run Python" (whatever that means!).

So that's one project. Another is called The Datatypes Project: Abstract Assembly. I will get into that later. Another is called The Archives-Project, and in part it is a new novel I've been working on for many years, but it goes much further than that. Also a topic for another time.

Right now, though, I want to introduce this cute little Python module simply called "wikipedia". The wikipedia module is going to help me actually compose the very first official Refcards app.

Installing it is simple, type:

$ pip install wikipedia

You can instantly start doing interesting things. Check out the documentation. Here is a simple example of what you can do, from the documentation:

>>> import wikipedia
>>> wikipedia.search("Barack")
[u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama']
>>> wikipedia.suggest("Barak Obama")
u'Barack Obama'

That's all there is to it, really. The possibilities are endless, though. Also from the quickstart guide, you can get a summary of an article simply, by using  wikipedia.summary:

>>> wikipedia.summary("GitHub")
2011, GitHub was the most popular open source code repository site.\nGitHub Inc. was founded in 2008 and is based in San Francisco, California.\nIn July 2012, the company received $100 million in Series A funding, primarily from Andreessen Horowitz.'
>>> wikipedia.summary("Apple III", sentences=1)
u'The Apple III (often rendered as Apple ///) is a business-oriented personal computer produced and released by Apple Computer that was intended as the successor to the Apple II series, but largely considered a failure in the market'

Anyway that's it for now. I will be coming back to this. Just keep an eye out for future blog posts on both The Internals Project AND The Refcards Project. The idea is that I can create a simple app that does nothing more, really, than reading out the first couple of lines from any given Wikipedia article.

The thing is, though, that with other Pythonic magic, it's pretty easy to take a module like the wikipedia module and make it do interesting things. For instance, I can not only fetch the first few lines of an article, I can also basically "crawl" the page for certain links. With a little Pythonic magic, some regular expressions or whatnot, or an interesting chunk of code called "pattern", I can do amazing things just with a simple Wikipedia page.

The module already lets me fetch the "categories" for a given page. Granted, I will need to do some Natural Language Processing magic, but that's pretty easy in Python. So basically I can create a simple app that interfaces with Wikipedia in amazing ways. I can make it get more intelligent AS YOU USE IT, and I can make everything get stored automatically on Dropbox, or even as Gist on Github using the Github API.

Python is amazing in that way, it has a million and one ways it has been extended, and the tools exist to do just about everything. Anything you can think, you can likely do in Python. With that being said, I don't like Python as a language. I think it is too slow. I think that if you're going to write code in Python, you should just learn to write it in C. Period. Don't use Python, use C. You're just wasting your time with just a bunch of bloat and candy and sugar. Fuck it, it's not worth it.

But it's the only language I currently know how to code in. So I "tolerate" it, at least until I finish learning how to write in C. And I'm getting there. But that might just have to be on another blog, since this blog is called Pythonic Reflections. But that's what the output of my reflections have been, so far, that if you're going to write in Python, learn to write in C. Don't waste everyone's time. It ends up in C in any case. Python is just bloated complicated and slow C code. It's like deciding to speak in English, but deciding to speak in English but backwards. Okay, people will understand you as long as they have a "Reverse The Backwards" interpreter. But it's a waste of time, you are better to speak "Forwards English rather than the Backwards variety.

In short, that's what Python is: Backwards C.