Friday, 27 April 2018

Teaching Blockchain and Distributed Ledger 2: Some Programming

In a previous post, I discussed examples of the work I have done on teaching introductory blockchain. In that post, a kind of 'unplugged' approach was being used; a paper-based game and exercises in starting to think through some issues.

Within this post some of the teaching programming examples used in the class and the logic behind them will be discussed. Health warning: These are simple examples; only meant to get some basic ideas across that the students can then build on.

1. Javascript version
This section looks at a producing a blockchain on a local machine - to build up the ideas gradually. Confession time, my starting point was the fantastic videos shown below from Simply Explained -Savjee - really nice introduction.






So as in the video Visual Studio Code was used to develop the solution; using JavaScript and running Node.js - a little bit of setting up is needed but certainly on a Mac or Linux machine it wasn't too difficult. So the code was built up and the following produced.
//adapted from the videos of Simple Explained -Savjee
//https://www.youtube.com/channel/UCnxrdFPXJMeHru_b4Q_vTPQ

const SHA256 =require('crypto-js/sha256');

class Block{
constructor (index,timestamp, data, previousHash = ''){
this.index = index;
this.timestamp = timestamp;
this.data = data;
this.previousHash = previousHash;
this.hash = this.calcHash();
this.nonce =0;
}

calcHash(){
return SHA256(this.index+this.previousHash+this.timestamp+JSON.stringify(this.data)+this.nonce).toString();
}

mineBlock(difficulty){
while(this.hash.substring(0,difficulty) != Array(difficulty+1).join("0")){
this.nonce++;
this.hash = this.calcHash();
}
console.log("Block mined hash: "+ this.hash);
}
}

class Blockchain{
constructor(){
this.chain = [this.createGenesisBlock()];
this.difficulty = 4;
}

createGenesisBlock(){
return new Block("0","13/3/2017","Start","0");
}

getLatestBlock(){
return this.chain[this.chain.length-1];
}

addBlock(newBlock){
newBlock.previousHash=this.getLatestBlock().hash;
newBlock.mineBlock(this.difficulty);
this.chain.push(newBlock);
}


isChainValidOne(){
for (let loop=1; loop<this.chain.length; loop++){
const current = this.chain[loop];
const prevOne = this.chain[loop-1];
if((current.hash != current.calcHash())||(current.previousHash != prevOne.hash)){
return false;
}
}
return true;
}
}

let educoin = new Blockchain();
educoin.addBlock(new Block(1,"10/7/2018", {name : "Ali", qual : "PhD", qual1 : "BSc"}));
educoin.addBlock(new Block(2,"10/7/2018", {name : "Scott", qual : "PhD"}));
educoin.addBlock(new Block(3,"10/4/2018", {name : "Scott", qual1 : "Swimming Certificate"}));

console.log(JSON.stringify(educoin,null,4));
console.log("Is the chain valid ? "+educoin.isChainValidOne().toString());

The idea of going down this route was the students are familiar with JavaScript so it follows on from what they know; promotes the idea that blockchains are not language specific and lastly the elements of the block and blockchain can be seen - without the language getting 'clever' and hiding how it is done.



2. Solidity
The second stage was build up an example to go onto the Ethereum blockchain. So I decide to show Solidity, which is a programming language for doing this. After experimenting with various options I decided to use the free (always good) online integrated environment from Ethereum called Remix (http://remix.ethereum.org/) and stick with the online version. Remix meant that there wasn't any extra installation, it is pretty self-contained and it comes from Ethereum itself. 

So the code produced is inspired by the #BlockchainEducationalPassport (https://blockchainedupass.uniteideas.spigit.com/Page/Home) project - but much simpler. The code sets up a record for a student (name and qualification) and adds it to a list/array of students.

pragma solidity ^0.4.0;

contract educoin1 {
        struct edRec {
            string name;
            string qual;
        }
        address public student;
        mapping (address => edRec) public Students;
        address[] studentsByAddress;
        
        
        function add(string _student, string _qual) public {
            address thisAddress=msg.sender;
            Students[thisAddress].name = _student;
            Students[thisAddress].qual=_qual;
            studentsByAddress.push(thisAddress);
        }
}

The figures below show a 'record' being added (figure 1) and then looking at waht is stored (figure 2)


Figure 1: Entering the record

Figure 2: Seeing the transactions
Following links to material on Solidity, the students were asked to alter the solution in ways that interest them.


3. Where next
The final section was to look at Distributed Ledger alternatives to Blockchain - but not the programming them so the Tangle used in IOTA https://www.iota.org/get-started/what-is-iota was discussed.


All views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Sunday, 22 April 2018

Teaching Blockchain and Distributed Ledger approaches 1

Recently started developing materials to teach blockchain to a group of MSc Computing students within a module on internet programming. So what is the problem? 

Not really a problem, but:

  • deciding where to start;
  • wanting the students to consider what are blockchain and distributed ledger techniques;
  • thinking like programmers about the techniques rather than the hype - they may in the future be the one who has to persuade someone to either go with a distributed ledger solution or equally not.
1. First teaching approach
My decision was to initially go with a flipped approach of providing a set of materials on blockchain before the session, expecting the students to use them with some guidance and following it with the 'blockchain game' and user case example activity.


2.The Blockchain Game


2.1 Rules You will be placed into groups by the tutor, please do not use the computer for anything else during the task part of the activity, but as a source of the rules of the activity. Each group will need

  • one sticky note/sheet of paper per group to store the 'blockchain'
  • paper and pen for each member of the group.
Please note groups are of different sizes on purpose - this is part of the exercise. 
Now your group's sticky note divide the note up in the same way as below.
Start of the blockchain game.


We are now ready to start the game.


Rounds in the game
1. The tutor will provide a new 'block' it will be in this case a single number each round, this is the data. (Note: in an actual blockchain this will be a much more complex bit of data).


2. To slow the system down, increase security - the winner needs to do some work. This is the Proof of Work concept. Each member of the group needs to individually calculate the new Hash value using the following rule:
HASH = Prev + (Data*25)-1255
3. Each group decides on their answer and is trying to be the first to give the correct answer. Only one answer per group at a time. Before starting the game the group will decide on a mechanism for giving the answer - e.g. agree and answer or first to get the correct answer says it.
4. The tutor will decide who wins - the decision is final.


5. The winning team gets the win and every group now writes down the data and the new hash BUT only after the winner has been found. also start a new block with the hash just being calculate written in as the previous hash in the new block.


6. So a blockchain has a new item in the blockchain and every group's blockchain is the same. Now go back to step 1 the games carries on until the tutor ends it.






2.2 Reflection activities
Groups that have only one member during the task join together now to be a new group called the 'one and only'. Groups with two members only will join together to be a single larger group called 'two's companies' and the group(s) with four or more members will join together to form a single group called 'hydra'
Step 1 Individually - no discussion at this time do the following (15 minutes)
1. What I have learnt during this activity?
2. Do you think there is some benefit to larger group sizes for this problem?
3. What do you think the role of the hash and proof-of-work is?
4. What do you think would happen if someone tried to alter the data in the middle of the blockchain after other blocks have been added?
Step 2 Group. (15 minutes)
Using the same questions 1 to 4 come up with, after discussion, a single set of answers for the whole group.
Step 3 Sharing. Each group will present their findings. (10 minutes)
When not presenting the other two groups are expected to listen, take notes where appropriate and after the presenting group has finished be prepared to ask questions.
Step 4 (outside of the class): To consider individually or as a group.
(a) Think about your individual answers, group's answer, new insights you gained from the other groups and from sources external to the class; then possibly revise your answers. 
(b) Can you improve the game, for example change it so it might take several iterations to get the right hash (look up how bitcoin does this - no need in the game though for SHA256)


3. User Case Activity
In this activity, the three groups are given three different scenarios; sample examples include a social solution, cryptocurrency or supply chain activity. They were asked to consider a range of issues that a programmer or developer might have to consider for example
- What data would need to be stored within the blockchain for this scenario?
- Who would hold and mine a copy of the blockchain?
- Why would someone hold and mine the blockchain? What is their incentive?
- Why not use a centralised database for the scenario?


4. Summary
These initial activities were purposely designed to not involve coding. Though the choice of programming language is not always independent of the approach, I believe cutting through to the requirements is a central part of the programming the solution, and this is largely independent of the approach.

In the next post in the series, I will look at the coding.


All views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Saturday, 21 April 2018

Teaching VR through the Web

This post documents my personal experience with teaching WebVR - Web based Virtual Reality within a module on Internet Programming. In this case, based on the wonderful A-Frame (https://aframe.io) and exploring it with MSc Computing students.

The three insights: 

  • It is great fun (which I did expect) to teach;
  • It is nowhere near as hard as I thought it was going to be when I first started;
  • Students seem to enjoy it


1. The approach
I needed a way of doing it that doesn't require a lot of setting up and can be done on a variety of machines. The approach used was using A-Frame (https://aframe.io) inside Thimble (https://thimble.mozilla.org ). Thimble was selected because it is an online editor,  simple to use, it is free and you see the preview immediately. One restriction to bear in mind is that the filesizes of images and videos have to be small though.



2. How easy is it?
You can treat it as if was HTML, after you have added the script file shown in bold.

    
   

The video below shows setting up and adding a box to the scene.



This next video takes this a little further by adding rotation to an object.

 

In this video below, mapping an image to an object and changing camera position is looked at.

 



3. Adding video
Actual in some ways it as easy to add video as adding an image, at it's simplest adding src="" with either the URL or relative filename in the speech marks can be used for both images and video. Alternatively using  combination with again the filename or URL between speech marks adds a block and pastes the video on top. The video below shows a worked example of these two approaches

 

4. 360 degree video.
A-Frame allows 360 degree to be incorporated into the scene using the  tag. The video below shows a worked example of this. The video below shows another worked example.

 

5. 3D objects and Assets
We can also add 3D models that others have developed into our scene. In the video below a Penguin, defined externally using .obj for the model and .mtl for the material, is loaded into the scene.

 



6. Overview
Teaching this was fun, and lends itself to a problem-focused approach. Small projects are set up and worked through but the visual nature I believe encourages experimentation. The students were very quickly able to develop their own small projects and were experimenting with a range of objects.

One interesting feature I found when looking around for supporting materials is there is a very limited range of books on A-Frame and WebVR but some fantastic resources online including the best place to start: https://aframe.io/docs/0.7.0/introduction/ 


All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Monday, 27 November 2017

What do students think of exam?

Ajit, S. (2017) Exam as an assessment instrument in computer programming courses: student perceptions. Poster presented to: 6th International Assessment in Higher Education Conference (AHE 2017), Manchester, United Kingdom, 28-29 June 2017.



Abstract
Assessment can take many forms, and it can be argued that the greater the diversity in the methods of assessment, the fairer, assessment is to students (Race 2007). The most effective form of assessment is one that appropriately examines the learning outcomes of the module. Assessment methods are also known to play an important role in how students learn (Brown 2004). The traditional assessment approach, in which one single written examination counts towards a student's total score, no longer meets new demands of programming language education (Wang, Li et al. 2012). Students tend to gain higher marks from coursework assignments than they do from examinations (Gibbs and Simpson, 2004). Students consider coursework to be fairer than exams, to measure a greater range of abilities than exams and to allow students to organize their own work patterns to a greater extent (Kniveton, 1996, cited in Gibbs and Simpson, 2004). Do students really hate exams? Are exams ineffective as an assessment approach in computer programming courses? A university wide research survey regarding assessment approaches in computer programming was conducted among students of undergraduate computing courses (including all three levels). 167 students participated in the survey. The author discusses some interesting results obtained from the survey. More than 50% of the students surveyed indicated that they would like examination to be a part of the assessment approach. The author explores possible reasons for this choice by students and compares these results with that of research conducted in other subject areas.







All views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Thursday, 2 March 2017

Science and Technology Free Open Educational Resources

In previous posts the availability on the JISC Jorum repository of six Open Education Resources (OERs) from the former School of Science and Technology (now part of the Faculty of Arts, Science and Technology) at the University of Northampton was discussed. After 13 years the Jorum repository was discontinued.

Three of the OERs though were migrated across to the JISC Apps and resource store and available for reuse.

1. C Programming


Now available at https://store.jisc.ac.uk/#/resource/8395.


















2. Summary of Evolutionary Algorithms


Now available at https://store.jisc.ac.uk/#/resource/8405























3. Properties of Ultrasonic Waves



Now available at https://store.jisc.ac.uk/#/resource/8232 













All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruonAll views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Saturday, 11 February 2017

Teaching Neural Networks using Excel and Scratch

Originally from https://computingnorthampton.blogspot.co.uk/2016/12/experiments-in-teaching-neural-networks.html

Excel Based







Scratch-based
More details available at https://computingnorthampton.blogspot.co.uk/2016/11/miniproject-using-scratch-to-build-and.html including links to the code.

 All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruonAll views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Teaching Genetic Algorithms with Excel


In a previous post I discussed using Scratch and Excel to model neurones. This post looks at using Excel and six-sided dice as a way of developing insights into how  Genetic Algorithm work, before going on to program one. 

A very simplified version of Tournament Selection is used for the parent selection and the mutation works by rolling a die to get a number between 1-6.

The problem to be solved is to find the lowest values for x and y in the equation 
(x-6)*(x-6)+(y-1)*(y-1).






Routine


  1. Using an Excel spreadsheet,  roll two dice six times. Fill in the first two columns with these numbers - these are X and Y values for each solution.
  2. The fitness scores should be calculated based on the equation. Low values for this problem are best.
  3. 1st Parent: Roll two dice, if the numbers are same reroll one die to until the numbers are different. Use the two values to select the 1st parent, the solution with the lowest fitness of the two. Take the X part of the selected parent and it forms the X part of the new child solutions.
  4. 2nd Parent: Roll two dice, if numbers are the same or appear in 1st parent, reroll until you get two different numbers (including different to the 1st parent). the solution with the lowest fitness of the two. Take the Y part of the selected parent and it forms the Y part of the new child solution.
  5. Mutation: Roll a die for each part of the child solutions. If the roll is 1, roll another die and replace the appropriate element with the new number – even if the same as the previous value.
  6. Copy the average  into the table and the lowest value 
  1. Copy the child solutions after mutation (orange) into the yellow area and repeat steps 1-6 10 times 





All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruonAll views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Green Apple Award for helping teach children to code

Taken from: http://www.northampton.ac.uk/news/university-of-northampton-receives-a-green-apple-award-for-helping-teach-children-to-code/


The University of Northampton has been praised for a competition it helped set up with the aim of improving the teaching of computer coding and school pupils’ technology skills.
The Race to the Top contest, which challenged children across the county to design a digital game or mobile app based around saving energy, was awarded a Gold Green Apple Award by the Green Organisation. These are awarded for projects which are considered to be demonstrative of environmental best practice within the public sector.
The winning teams were from Park Junior School in Wellingborough and Kettering Buccleuch Academy who came up with a game which challenges players to fix degrading solar panels on the school roof and an app which tracks household energy consumption.
The competition was organised by the University of Northampton, in partnership with Northamptonshire County Council, Code Club and the Worshipful Company of Information Technologists (WCIT).
The initiative was part of Northamptonshire’s school improvement strategy and the award was presented at a recent ceremony at the Houses of Parliament in London.
Dr Scott Turner, Associate Professor in Computing said: “The feedback we received from the children has shown that the Race to the Top contest has enthused them and having the opportunity to come to the University campus for the celebration event was a real confidence boost and they really enjoyed it.”


All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruon

All views are the authors, and may not reflect the views of any organisation the author is connected with in any way.

Sunday, 27 November 2016

Unplugged Artist's Chapter

A recently released book Teaching Computing Unplugged in Primary Schools  edited by Helen Caldwell (University of Northampton) and Neil Smith (Open University) has a number of interesting chapters by authors who are passionate about how computing is taught in schools. The central theme is unplugged activities, without using computers, but still teach the fundamental of computational thinking.

Ok, confession time. I co-wrote, along with Katharine Childs (Code Club), Chapter 3 Artists so I am biased here, but I believe in the central theme of Unplugged Computing. Computing, and Computational Thinking in general,  is not just about programming and using a computer (though using computers and  programming are vitally important to Computing) but it is also about many other things including problem-solving, being creative and working collaboratively.

Chapter 3 is about linking these computational thinking ideas to produce visual art, by applying computing principles including  repetition, following and refining algorithms, and abstraction. The chapter also looks, how these links have already being made, with examples such Sol Le Witt where not all the work that was produced by the artist himself, but some by others following his written instructions - in other words an algorithm. An example activity is shown below (named after my son who was the first to play it).

Thomas’ Tangles
Exploring abstract patterns using randomness within an algorithm.

Using crayons, pencils or pens, we are going to follow an algorithm to create a random drawing. This could be done in pairs and you will need squared paper.
Person A: Rolls the dice and reads out the instructions.
Person B: Is the ‘robot' carrying out the instructions.

IMG_0226.JPG

When the starting or central square is blocked and a new central square is needed the roles of A and B swap (so A is the ‘robot’ and B rolls the dice and reads out the instruction). The roles keep swapping.

Algorithm

Start from a random square – call it the centre square
Repeat until end of game
If die roll = 1
Roll die for number of moves
Check for blocks
If not blocked then
move die roll number of steps up the page
If die roll = 2
Roll die for number of moves
Check for blocks
If not blocked then
move die roll number of steps down the page
If die roll = 3
Roll die for number of moves
Check for blocks
If not blocked then
move die roll number of steps to the left
If die roll = 4
Roll die for number of moves
Check for blocks
If not blocked then
move die roll number of steps to the right
If die roll = 5
Roll die
If die = 1 change colour to Red
If die = 2 change colour to Blue
If die = 3 change colour to Black
If die = 4 change colour to Red
If die = 5 change colour to Orange
If die = 6 change colour to Yellow
If die roll = 6
Return to current centre square

Check for blocks:
If pathway blocked do not move then
reroll die
If number of spaces in the direction > die roll then
move until blocked
If all pathways blocked then
choose a new centre square



The other chapters make links with areas such as Robots, Musicians, Explorers, Magicians, Gamers, Cooks and Scientists.


References

Barr, D., Harrion, J., and Conery, L. (2011) Computational Thinking: A Digital Age Skill for Everyone Leading and Learning with Technology, ISTE, March/April 2011 [accessed via http://www.csta.acm.org/Curriculum/sub/CurrFiles/LLCTArticle.pdf on 26/12/2015]
Barr, V. and Stephenson, C. (2011) Bringing Computational Thinking to K-12, ACM Inroads, Vol 2. No 1, pp 48 - 54 [accessed via http://csta.acm.org/Curriculum/sub/CurrFiles/BarrStephensonInroadsArticle.pdf on 26/12/2015]
https://doi.org/10.1145/1929887.1929905
Computing at School (2013) Computing in the National Curriculum: A guide for primary teachers [accessed via http://www.computingatschool.org.uk/data/uploads/CASPrimaryComputing.pdf on 13/3/2016]
Denning, Peter J. (2009) Beyond Computational Thinking, Communications of the ACM Vol 52, Issue 6, pp 28 - 30 [accessed via http://sgd.cs.colorado.edu/wiki/images/7/71/Denning.pdf on 26/12/2015]
DfE: Department for Education (2013) National Curriculum in England: computing programmes of study
Freedman, J. (2015) Cycloid Drawing Machine [online] URL: https://www.kickstarter.com/projects/1765367532/cycloid-drawing-machine accessed on 3/3/2016.
Google. 2016 Project Jacquard [online] URL: https://www.google.com/atap/project-jacquard/ accesed on:1/3/2016.
Knuth, D. 1968. Preface, The Art of Programming vol 1., Boston: Addison-Wesley.
Knuth, D. 1996. Foreword. In: Petkovsek, M., Wilf, H., Zeilberger, D. A=B.. Natick: A K Peters/CRC Press, vii.
Koetsier, T., 2001. On the prehistory of programmable machines: Musical automata, looms, calculators. Mechanism and Machine Theory, 36(5), 589-603.
https://doi.org/10.1016/S0094-114X(01)00005-2
Menegus, B (2016) CDMS: Built with Processing [online] URL: http://wheelof.com/sketch/ accessed on 4/3/2016
MoMA. 2012. MoMA| Video Games [online] URL: http://www.moma.org/explore/inside_out/2012/11/29/video-games-14-in-the-collection-for-starters/ accessed on: 1/3/2016.
Papert, S (1993) The children's machine: Rethinking schools in the age of the computer. New York: Basic books
Pearson M (2011) Generative Art: A practical guide using Processing, New York: Manning, 3-12
Selby, C. and Woollard, J. (2013) Computational thinking: the developing definition University of Southampton [accessed via http://eprints.soton.ac.uk/356481/7/Selby_Woollard_bg_soton_eprints.pdf on 26/12/2015]
The Art Story (2016) Sol LeWitt [online] http://www.theartstory.org/artist-lewitt-sol.htm accessed on: 6/3/2016
Wing, J. (2006) Computational Thinking Communications of the ACM Vol 49 pp 33 - 35 [accessed via https://www.cs.cmu.edu/~15110-s13/Wing06-ct.pdf on 26/12/2015]
https://doi.org/10.1145/1118178.1118215
Wing, J. (2011) Computational Thinking - What and Why The Link - News from the School of Computer Science, Issue 6.0, Spring 2011 [accessed via http://www.cs.cmu.edu/sites/default/files/11-399_The_Link_Newsletter-3.pdf on 26/12/2015]
Liukas L (2015) Activity 7 The Robots Hello Ruby - Adventures in Coding, New York: Feiwel and Friends, 94-97.
Schofield, S (2016) Generative Artworks [online] URL: http://www.simonschofield.net
Turner S (2016) 3 'Art' Scratch Projects [online] URL: http://compuationalthinking.blogspot.co.uk/2016/03/3-of-my-scratch-projects-for-week.html accessed on: 12/3/2016.







All views and opinions are the author's and do not necessarily reflected those of any organisation they are associated with. Twitter: @scottturneruonAll opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruonAll views are the authors, and may not reflect the views of any organisation the author is connected with in any way.