Sunday, October 31, 2021
Friday, October 29, 2021
Main
Found the use of this mysterious bit of python code:
It is instructions to the interpreter to run this file as the main one. Because a project
can easily have more than one .py file in it, and one needs to check if it is one that is
imported or one doing the importing...
* * *
The underscore, in Python, is generally used to print the last output. It can
also bee used as a nameless variable.
By convention, coders use it to tell later users of some code to keep something private.
Pythonesque
Been trying migtily to get a grip on python: multipurpose language,
object-oriented, blah, blah. Then I saw a quote from G van Rossum wherein
he said he had developed python to faciitate working with data. That
makes sense.
C is arguably the fastest language to get things done, but it is long-winded and tedious
to write. python is breezy but its interpreter is written is C, so it will take comparatively
longer to execute. The interpreter translates python code to bytecode, which then
runs on a virtual machine. Re bytecode:
'Byte code is an intermediate code between the source code and machine code. It is a low-level code that is the result of the compilation of a source code which is written in a high-level language. It is processed by a virtual machine like Java Virtual Machine (JVM).
Byte code is a non-runnable code after it is translated by an interpreter into machine code then it is understandable by the machine. It is compiled to run on JVM, any system having JVM can run it irrespective of their operating system. That’s why Java is platform-independent. Byte code is referred to as a Portable code.'
Geeks for Geeks
As for what lives where, Python3.9 comes with libraries. Modules are functions, groups of
related modules are packages, and packages travel as librairies. A package has an __init__
functionthat calls the appropriate module. Pip install will make move a module's contents
to an easily accessible file.
As an exercise, I am importing the sys module and asking for a print of sys.path. i will see
where the machine will look for sys functionality as needed:
Wednesday, October 27, 2021
Stingy
Corpus0 is he simplest case, with diagram showing links below.
How should it pagerank.
I re-did the two approaches, sampling and iteration, but with much
smaller number of cases. There is even more difference...
With 10 000 sample for approach 1, and .00005 threshold on 2.
Going stingy with 100 sample, and .005 threshold on 2.
Tuesday, October 26, 2021
P_Rank
Anyone who uses Google has some notion of pagerank: it is the algorithm
that for any specific request, ranks the most popular sites. The first assignment
of the uncertainty lecture aims to code for a pagerank.
It may be easy enough to follow users from site to site, but describing such
a system gets bogged down in sollipsistic cycles. There are some sites that only
lead to a few others,- like apple pie recipes - so that randomizing algorithm risks running
in circles. To counter this, a dampening factore of 0.85 probability places the program
in popular sites, and 1 - 0.85 probability covers access to any page, including
the one we are on.;it is always possible to get out.
One writes the transitions code, a sampling approach (10000) and an iteration.
There are three corpus sets to test the code against.
Monday, October 25, 2021
Markov
Starting off this post with a photo of Russian mathematician Andrey Markov(1856- 1922)
for the very simple reason that he was rather good-looking.
His area of interest was stochastic processes ( ones where randomness is involved); and he
is known for Markov chains, essentially the idea that, as the Russian-language Wikipedia entry put it -
the past does not influence the future. Below, a Markov chain with probabilities attached for
each one-step alternative:
* * *
Nothing terribly surprising in this model. Starting on a 50/50 chance of rainor sun, each
run prints out a plausible sequence...
* * *
The second model introduces a bit of a twist: it is the probability of sun followed by rain
that is given! A camera captures whether emploees are entering the building with an umbrella.
I ran number 2 a number of times, and the results are always the same.
Sunday, October 24, 2021
Flowering
Took one of my plants in a few days ago - a desert plant -, and it has flowered.
It doesn't flower every year; thought I'd share...
Saturday, October 23, 2021
Bake It
Pomegranate isreally wonderful. One can build up a model
very simply. Below, the train model:
Once all ia done; bake()Friday, October 22, 2021
Alpha
Baysian analysis allows for joint probability, below:
If I add the two columns, I get back to the 'rain in the afternoon' set of probabiities.
If I add across rows, I return to the 'clouds in the morning' numbers. So what is likely to
happen on any given day: no cloud and no rain; cloud and no rain; cloud and rain;
no cloud and rain. In that order...
* * *
I can also ask a 'time-inverted' question. What is the probability of having experienced
cloud in the morning , given it is raining in the afternoon.
Alpha, here, is used to produce a standard probability distribution that adds to 1!
* * *
Just nstalled pomegranate, a probabilistic programming library for python.
Tomorrow...
Thursday, October 21, 2021
So Done
So, what kind of magic is this!? What Bayes' Theorem is addressing is
conditional probability. Math is Fun gives us a clear view of what this concept
refers to: the probability of an occurence, given a previous one...
The two draw events are independent, but the conditions have changed:
* * *
How Bayes' T can be derived:
Interestingly, Thomas Bayes(1702 - 1761) was a compatriot of David Hume(1711 - 1776) who
- famously - defined causality in experiential terms: the constant conjunction of events.
* * *
Wednesday, October 20, 2021
Wiki Help
Biting the bullet on Bayes' theorem. This seems harmless enough,
but it is the basis on which links are made between medical test
results and disease...
Thank Heavens for Russian Wikipedia, which presents the argument as follows:
Tuesday, October 19, 2021
Painful
Looking to start work on the Uncertainty lecture from
CS50 AI.
It will involve Bayesian analysis:
My brain hurts already...
Sunday, October 17, 2021
Computer Play
How the computer plays: it plays quickly!!
* * *
Benn playing with changing the number of mines in the game (line 9 on runner.py).
Below, a game with 10 mines led to this punishing outcome on the last move.
Ai had been on a run of safe moves up to there...
So there is an element of chance that can sneak back in, and hence one won't always win...
Another mines10 that flips into random mode, even with a move 1 to a 0 tile!!
Loss on eight:
Saturday, October 16, 2021
Works!!
Finally found a version of minesweeper code that works
(on PyCharm). Will be examining code tomorrow:
https://github.com/MoosaSaadat/minesweeper
Friday, October 15, 2021
Digging In
Comes down to learning python and AI at the same time.
For python functions:
https://realpython.com/python-return-statement/
Been following along with this youtube :
Makes perfect sende: every cell that is a mine is worth 1,
every cell that is safe is worth 0.
TDrop
Getting ready for the big temperature drop this week-end.
Back to seasonal,essentially from daytime highs of 20 to teens.
Thursday, October 14, 2021
The Challenge
I had forgotten just how challenging this game is. Below, some modest
beginner solutiions...
https://cardgames.io/minesweeper/
Srarting to see where the computer will outclass me: solved this last one
at the very end by considering how many mines were left to be played.
Such a procedure would be mindbending on a larger board...