Tuesday, November 30, 2021

R_Learning

Finishing up the AI lecture on Learning, below reinforcement Learning.


The agent - represented by the yellow dot - learns to move to the green space
at the expense of a penalty for giong to a red square, and otherwise a reward.


It is a Markov Decision Process, similar to a Markov Chain.

 

Fitness Time

 Found a fitness provider with no pain, no sweat videos that

are still terribly useful. I don't listen to his instructions, but

use the translation to get what he is saying. works fine...👩‍🦳



Saturday, November 27, 2021

Rant

 Got frustrated today, trying to eaccess an article on Diabetes1 in today's

New York Times, without actually taking out a subscription; this where

the French dailies are more humane. One can, for a few Euros, read anything

one wants.

https://www.nytimes.com/2021/11/27/health/diabetes-cure-stem-cells.html

Still, did find a review article on the research issue:

https://www.nature.com/articles/d41586-021-01842-x


                                         *     *     *

Also been giving a listen to the odd rant by young Dr Bernard, a few years back.

He is sooo right: eat less and move more is what the obese would like to do,

if their situation were different!Duh!!



Friday, November 26, 2021

Evaluating Models

 Back to the AI lecture. Installed a new module:


*     *     *

Left-off with the issue of loss functions to evaluate our model. Loss1 shows 

a simple count of cases that the model doen't pick up. L2 penalizes a large

discrepency that is not picked up:



Overfitting the data can sometimes lead to a model that describes the data perfectly,

but is a weak predictor for that very reason.




The way around this problem is to add a complexity element, whose value we will

choose to weed out too precise fits.


One can easily enough divide our data between a learning set and a testing set.

Best to do this in multiple configurations.



Python has libraries that will handle all this for us. This is sklearn I have installed.

Working with data on serial numbers from US bank notes, and knowing which are

genuine and which are counterfeit, one can see how the different models perform:











Tuesday, November 23, 2021

SVM

 Going back to the AI lecture, got an introduction to the Support-Vector

Machine (SVM), a machine learning algorithm to classify data points or

find a linear solution. The idea is to arrive at a demarcation so that new data

can fit into one category or the other ie a classification, that can take the form

of a straight line or a higher dimensional form. Its adequacy is ensured by maximizing

the distance from individual data points.

No:



Yes:



Finding a higher dimension decision boundary:




So how does one choose between approaches for a problem ?! By seeing

how poorly our  model performs.




Prudent

I did again: took a fall on the first snowy day. Thankfully,

my bum took the hit this time and not my arm as happened a few

years ago. Why does this happen to me: because, the first day of 

snow on the ground is often a sub-zero day and there is ice under

those innocent-looking white sidewalks. If this happens later in the

season, it is not so bad because there is a build-up layer of salt and grit 

under the snow. On the very first snowstorm, NOT.


I have lived in Canada long enough to be alerted to this, but I forget 

and walk along thinking of this and that. I need to concentrate and take 

little careful steps. That, or wait till the city snow crews have done their 

work.👩‍🦳

                                                     *     *     *




Monday, November 22, 2021

Travel

 Don't mean to troll Thanksgiving travellers, but Beijing to Shanghai

is roughly the distance between New York and Atlanta. And 500 Renminbi

comes to 78 USD!!



Sunday, November 21, 2021

C_Learning

 Started on the AI learning lecture. The lecturer points out that a human being has difficulty

visualizing linear relationships in more than 2 or three dimensions; not so for a computer.

It's all a series of tuples for the machine.This is going to be brutal!!!



Fine, using data on humidity and pressure, find the line that allows one to 'predict'

whether it is raining or not.

Easy enough to tell here that it is raining:


A simple neaest-neighbor test will do the trick. but what about this situation:



Got it!

                                                                        *     *     *

Fancier yet:


The weights in this case are the coefficients in the linear expression describing our

rule, above.


  *     *     *










Saturday, November 20, 2021

Ongoing __Vancouver

 Been following events in BC from The Guardian UK. One

needs to enter from the International edition.





*     *     *

From the Vancouver Sun




                                                          *     *     *

Building differently:

Friday, November 19, 2021

BC

 For an overview of the situation in BC, found this in the Guardian UK:

https://www.theguardian.com/world/2021/nov/18/residents-brace-for-torrential-rains-in-already-flooded-western-canada

                                                *     *     *

Atmospheric river': the term was coined in the 1990s. These are narrow water 

plumes in the upper atmosphere, that can be thousands of kilometers long but 

only a few hundred wide. Quite normal, and how rains travel to the Western Coast 

of America and Europe. But at this intensity, clearly part of the climate crisis.

 Experts had warned the Fraser Valley in the BC interior woud be hit more often 

and with greater severity.  The rain there is 'orographic' ie over a mountain ridge...

(Wikipedia)




Tuesday, November 16, 2021

Finds

 I'm off again this morning, to get vaccinated. It is my annual

flu shot. Not a big deal, but it does feel like I'm getting jabbed

a lot these days. To the point where I have been thinking I

should buy cardigan sweaters for all there medical events 👩‍🦰


As the news on Glasgow has been coming in, I have started to wonder

if the Covid-19 pandemic is a heated up world phenomenon. Higher

populations, more international travel, more people in cities, more tourists

and even mountain-climbing eco-tourists and so forth. The current resurgence 

of Covid cases in Europe is being partially blamed on cold weather because

the virus stays in the air longer in colder temperatures. Equally important,

high levels of CO2 in indoor environments promote transmission: we are breathing

in each other's expelled CO2, and there needs to be ventilation standards in

schools, offices and workplaces.


I've been watching a lot of youtube lately. Thought I'd share some of my 'finds'

for today.

                                              *     *     *                    


                                              *     *     *


                                             *     *     *


                                            *     *     *

Sunday, November 14, 2021

Diabetes Day 2021

Today is Diabetes Day. An interesting overview from the Montreal Gazette:

https://www.healthing.ca/diseases-and-conditions/diabetes/the-history-of-diabetes-november-14-marks-100-years-of-insulin/

Time Scales

 There is skepticism about the Cop26 agreement. It's another 'let's meet again

and try to do better' agreement. On the plus side: coal is now part of the discussion.

There also remains frustration on the part of poorer and smaller countries - often the

most impacted by droughts, or storms and sea level rises -  and at the same time with the 

least power to affect outcomes. And dangers for many plant and animal species.



source: BBC

But then, on a very long time scale, Earth is getting slower and colder and life

on the planet  will seek to adapt. Dizzying to contemplate...

Thursday, November 11, 2021

Inflation_Calc

 Playing with the Bank of Canada inflation calculator this morning:



https://www.bankofcanada.ca/rates/related/inflation-calculator/

                                                      *     *     *

Bloomberg US:




                                                                 *     *     *




Wednesday, November 10, 2021

CrossWord

 Moving on from yesterday, there are certain heuristic practuces that

make traversing a nodes and arcs image easier:

- Enforcing arc consistency atevery move will solve it - if there is a solution -

without backtracking

- Choosing to begin with the node with the largest number of domain elements.

- From domain elements, choosing the one with the fewest links...


The assignment from this lecture is kinda exciting to me, because I am such a huge

scrabble fan. It is generating a crossword puzzle from a given wordlist that the AI

will then solve.




From code:

https://github.com/dtemir/harvard-CS50AI/blob/master/crossword/generate.py



                                                           *     *     *


So how does the code create a crossword puzzle exemplar. We are given

structures (word length) and word lists to work with. the code enforces node consistency 

(on a word) and arc consistency (on a pair) who must exhibit similar letters at required places.

Where that is impossible, backtrack tries agin with another word. The output is the

'solved' image.


Note that a variable is a word space in the puzzle: with two position values, across or down,

word length.

A neighbor is another variable in the puzzle.

An assignment is a word.

Tuesday, November 9, 2021

Congrats

 Sunday was municipal elections in Quebec. Of the 1108 municipalities in the

province, some 210 now have women mayors, including Montreal's Valerie Plante.

St-Jean sur Richelieu joined the list on this election.

Congratulations to all !

Monday, November 8, 2021

Solutions

 Been working through ther exam scheduling problem.  One needs to

upgrade pip and install the constraint module for all the code:



                                                            *     *     *

An example of aconstraint satisfaction problem. Courses A to G need to be

schedules so that no one has two exams at the same time...


Backtracking manually to find one solution:


Doing it with difficult to write code:


doing it with simple code that calls the constraint module:


Voilà, there is more than one solution.

                                                              *     *     *

A simple constraint satisfaction problem:



Our approach uses nodes and edges:



The nodes represent the exams.There are only edges between them if there

is a constraint, here, same student. Each is called an arc.

As a rule, one looks for node consistency first; that would be whether all courses have

exams, not a problem in this case.

Then one looks for arc consistency: can one remove domains from a variable - here, a 

possible exam day - and keep going. 





If not, one reports a failiure and backtracks to start again with another variable.


The algorithm as a whole is called AC-3, Arc Consistency -3.









Sunday, November 7, 2021

Optimize

 Sat through what simulated annealing as an optimizing approach

is. Boils down to moving to next neighbor but allowing moves that

are slightly less good, at the beginning, to eventually phase this

behavior ut and - hopefully - find the true optimum. 


Moved on to linear programming. Turns out that python has an import

for that called spicy.optimize. Had to read up on np complete problems and

simplex optimization.


An np complete problem (nondeterministic polynomialtime complete) has to 

run through all the possible combinations to find the optimal one. The brute-force

approach!! There are no sure shortcuts into it. What blouse looks best with what

shorts given white sneakers?? Take everything out and try it on!!


Linear programming problems describe a linear relationship with constraints.

How long should I run each machine given tat the first costs $50 per hour

and the second $80. My constraints: machine1 requires 5 workers per hour and machine2 2;

machine1 produces 10 units per hour and machine2 12. The optimize module tells me 

machine1 1.5 hours; machine2, 6.25, See below:



Gaussian algebra solves it, but why spoil the fun??


                                                          *     *     *

I had a question from someone: why does the 90 units of production

have to be treated in the negative. Short answer, because it is an upper

bound ('limite supérieure') . I have an order for 90 chocolate cakes and I can

deliver more but not fewer. It has to be stated in this form to meet the condition...


What_Happened

 


https://www.theguardian.com/us-news/2021/nov/07/rapper-travis-scott-devastated-after-astroworld-festival-deaths-houston

https://youtu.be/aQIEnyurC4c

My own take on this tragic occurence:

A young ineperienced crowd, weary ofpandemic restrictions. 

A misunderstood notion of mosh pits (probably how Metal Bands came to

'loosen' to tight crowds at their own events.

...

Saturday, November 6, 2021

Goals

  It saddens me to see so many young people at COP26 - and

even older adults - decry the failiure of the current exercise and 

accuse one and all of 'greenwashing'. I remember how panicked we 

were at the time. renewables sounded very nice in principle, but in 

practice were a nightmare because the energy they generated could not 

be stored, or easily transported. And would be dependent on abundant

 sunshine, not very likely here in Canada in the winter months.


Granted things do not seem to be changing overnight, but a petrol free future 

is in the works. In 1972, the report of the Club of Rome the Limits to Growth 

came out; to my mind, that was the year we became a planet, and not just the 

citizens of this or that country. That was a momentous change.


Low and behold, today solar energy can be stored, at large scale, and transported, 

across continents. And nobody worries about the neighbors...And we have electric

cars in the cities, with recharging points and Big Oil didn't sabotage anybody.

All my paper and plastic gets recycled - how were we ever going to get ordinary

citizens on board for that - and one can bicycle in Paris; how did that happen in

this most urban endroit.


The myriad changes I have lived through, computers and total connectedness not

the least of them, argue that we have not failed to adapt. We just need to take a moment

and feel a bit better about ourselves.


So the crunch at the moment is how to 'phase out' oil and gas. I am not concerned about

the calendar, but I do think we need goals about what to change next. Indeed it might

take quite a bit of oil and gas to build and maintain for the thechnologies of the future,

but with planning and good will, we can make it.



The energy is stored in a molten salt tower...

https://www.independent.co.uk/climate-change/opinion/cop26-summit-glasgow-fossil-fuels-b1952244.html


Friday, November 5, 2021

Simple Code

 Been running a few tests to see what we're talking about, here.

For simplicity, using only three houses and the requisite three hospitals.


Test1 is model perfect:



The second test, however, less so.



We're down to 7, but everyone is going to the same hospital!!!

Below, running again, but with random restart at 20.





                

                                       

Not too shabby: we got a four on run 4!