1548298346
Solidity is a high-level language used to implement smart contracts. This is an object oriented language designed to target the Ethereum Virtual Machine. Let's explore it!
Let's create a file called Contract.sol
First, you must define the version you are using. This is an information the compiler needs.
pragma solidity ^0.4.22;
All code in Ethereum belongs to a Contract. Let's create a contract and define a few variables inside it.
pragma solidity ^0.4.22;contract DeveloperFactory {
// Let’s create a Developer!
uint dnaDigits = 16;
uint ageDigits = 2;
}
Solidity is a typed language. uint stand for Unsigned Integer ( non negative integers ). These variables are state variables. They will be permanently stored in the contract storage ( in the Ethereum Blockchain ). Our Developer has a dna of 16 digits and an age of 2 digits.
Let’s keep going!
pragma solidity ^0.4.22;contract DeveloperFactory {
// Let’s create a Developer!
uint dnaDigits = 16;
uint ageDigits = 2;struct Developer { string name; uint dna; uint age; }
The struct variable allows us to define more complex data structures. Here the Developer struc takes a string called name, a uint called dna and a uint called age.
Solidity also has arrays. You can create dynamic or fixed arrays. Here, our Developer array is dynamic because we do not specify a length. So we can keep adding Developers to our army without any limitations.
Developer[5] public developers is a fixed array that can contain 5 Developer struct.
A function would look something like this:
pragma solidity ^0.4.22;contract DeveloperFactory {
// Let’s create a Developer!
uint maxAge = 100;
uint minAge = 5;struct Developer { string name; uint id; uint age; } Developer[] public developers; function _createDeveloper( string _name, uint _id, uint _age ) private{ developers.push( Developer( _name, _id, _age ) ); } function _generateRandomId( string _str ) private pure returns (uint){ uint rand = uint(keccak256(_str)); return rand; } function createRandomDeveloper( string _name, uint _age ) public view { require(_age > minAge); require(_age < maxAge); uint randId = _generateRandomId( _name ); _createDeveloper(_name, randId, _age ); }
}
We create functions with the function keyword. Functions can take parameters. By default, functions are public. I added the private keyword to make this function private. I also chose to add an underscore before a private function or variable to distinguish them from public variables. You don’t have to do this, I just find it easier to read.
Ethereum has the hash function keccak256 built in. This is a version of SHA3. Pass it any string and you get a 256-bit hexadecimal number.
As you can see, we are typecasting the keccak256 value into a uint value and we return it.
Aside from the private keyword, there are several things you can add to a function:
We have three functions. _generateRandomId generates a random Id for our developer by using the keccak256 built in function. _createDeveloper creates and pushes a new Developer struct into our developers array. createRandomDeveloper is the only public function. It checks if the age provided is correct. The require statements will throw errors if it is not the case ( age greater than 100 and lower than 5 in our case ). So, this last function is the one that can be called from outside our contract.
You can also create events so you can communicate what happens on the blockchain to your front-end app. Your app would then listen to those events and react accordingly.
pragma solidity ^0.4.22;contract DeveloperFactory {
// Let’s create a Developer!event NewDeveloper(uint devId, string name, uint age); uint maxAge = 100; uint minAge = 5; struct Developer { string name; uint id; uint age; } Developer[] public developers; function _createDeveloper( string _name, uint _id, uint _age ) private{ uint id = developers.push( Developer( _name, _id, _age ) ) - 1; newDeveloper(id, _name, _age); } function _generateRandomId( string _str ) private pure returns (uint){ uint rand = uint(keccak256(_str)); return rand; } function createRandomDeveloper( string _name, uint _age ) public view { require(_age > minAge); require(_age < maxAge); uint randId = _generateRandomId( _name ); _createDeveloper(_name, randId, _age ); }
}
After struct and arrays, we can also store data in mappings. Mappings are a key-value store. For example:
mapping(uint => string) public keyUintStringValue;
mapping(address => uint) public addressToUint;
Here, we have two public mappings. The first one has a uint key and a stringvalue. The second has an address key and a uint value.
The Ethereum blockchain is made up of addresses. Each account has an unique address. It takes the following form: 0x0cE440255306E921F41612C46F1v6df9Cc969183. Each address has a certain amount of Ether, which is the cryptocurrency used on the blockchain, and can receive or send Ether to other addresses.
With that in mind, let’s create a new mapping for our DeveloperFactory:
pragma solidity ^0.4.22;contract DeveloperFactory {
event NewDeveloper(uint devId, string name, uint age); uint maxAge = 100; uint minAge = 5; struct Developer { string name; uint id; uint age; } Developer[] public developers; mapping (address => uint) public ownerDevCount; mapping (uint => address) public devToOwner; function _createDeveloper( string _name, uint _id, uint _age ) private{ uint id = developers.push( Developer( _name, _id, _age ) ) - 1; NewDeveloper(id, _name, _age); } function _generateRandomId( string _str ) private pure returns (uint){ uint rand = uint(keccak256(_str)); return rand; } function createRandomDeveloper( string _name, uint _age ) public view { require(_age > minAge); require(_age < maxAge); uint randId = _generateRandomId( _name ); _createDeveloper(_name, randId, _age ); }
}
In the first mapping, we will keep track of the number of devs each account ( address ) created. In the second, we will keep track of the owners for each dev.
Each contract is passive, they don’t do anything until someone triggers them. msg.sender is a global variable that allows us to know which address is responsible for the triggering. It could be a account or another smart contract.
With that information, we can update our mappings appropriately. In the _createDeveloper function, we will increase the ownerDevCount for this particular address. In the devToOwner mapping, we will indicate that the newly created developer is owned by the msg.sender address.
pragma solidity ^0.4.22;contract DeveloperFactory {
event NewDeveloper(uint devId, string name, uint age); uint maxAge = 100; uint minAge = 5; struct Developer { string name; uint id; uint age; } Developer[] public developers; mapping (address => uint) public ownerDevCount; mapping (uint => address) public devToOwner; function _createDeveloper( string _name, uint _id, uint _age ) private{ uint id = developers.push( Developer( _name, _id, _age ) ) - 1; ownerDevCount[msg.sender]++; devToOwner[id] = msg.sender; NewDeveloper(id, _name, _age); } function _generateRandomId( string _str ) private pure returns (uint){ uint rand = uint(keccak256(_str)); return rand; } function createRandomDeveloper( string _name, uint _age ) public view { require(_age > minAge); require(_age < maxAge); uint randId = _generateRandomId( _name ); _createDeveloper(_name, randId, _age ); }
}
Notice the ++ notation to increase the ownerDevCount[msg.sender], just live Javascript!
Contracts can inherit from other contracts. If you open a new file call DeveloperLearning.sol, you can make it inherit from DeveloperFactory.sol:
pragma solidity ^0.4.22;import “./DeveloperFactory.sol”;
contract DeveloperLearning is DeveloperFactory {
// I have now access to DeveloperFactory functions
}
Notice how we imported the DeveloperFactory contract ( assuming it was in the same folder ). To declare inheritance, we use the keyword is.
In order for a contract to receive ether, we need to have the payable keyword to a function. The amount sent will be accessible in the global variable msg.value. So we could make sure that a certain amount of ether is sent to the contract before the creation of a developer:
pragma solidity ^0.4.22;contract DeveloperFactory {
event NewDeveloper(uint devId, string name, uint age); uint maxAge = 100; uint minAge = 5; struct Developer { string name; uint id; uint age; } Developer[] public developers; mapping (address => uint) public ownerDevCount; mapping (uint => address) public devToOwner; function _createDeveloper( string _name, uint _id, uint _age ) private{ uint id = developers.push( Developer( _name, _id, _age ) ) - 1; ownerDevCount[msg.sender]++; devToOwner[id] = msg.sender; NewDeveloper(id, _name, _age); } function _generateRandomId( string _str ) private pure returns (uint){ uint rand = uint(keccak256(_str)); return rand; } function createRandomDeveloper( string _name, uint _age ) public payable { require(_age > minAge); require(_age < maxAge); require(msg.value == 5); uint randId = _generateRandomId( _name ); _createDeveloper(_name, randId, _age ); }
}
In Solidity, there are two places where variables are stored: in storage or in memory. A variable stored in memory is temporary, it exists while the function is used, then it is discarded. A variable stored in storage exists permanently on the blockchain. Most of the time, you don’t have to worry about where to store your variables, as Solidity handles it for you.
For example, state variables ( maxAge, minAge, Developer ), declared outside of functions, are stored in storage. Variables like randId, id, rand are stored in memory.
But, in some cases, you want to explicitly declare where to store certain variables. Solidity allows you to do that with memory and storagekeywords.
#blockchain #bitcoin #solidity #altcoins #cryptocurrency
1598891580
Recently, researchers from Google proposed the solution of a very fundamental question in the machine learning community — What is being transferred in Transfer Learning? They explained various tools and analyses to address the fundamental question.
The ability to transfer the domain knowledge of one machine in which it is trained on to another where the data is usually scarce is one of the desired capabilities for machines. Researchers around the globe have been using transfer learning in various deep learning applications, including object detection, image classification, medical imaging tasks, among others.
#developers corner #learn transfer learning #machine learning #transfer learning #transfer learning methods #transfer learning resources
1620898103
Check out the 5 latest technologies of machine learning trends to boost business growth in 2021 by considering the best version of digital development tools. It is the right time to accelerate user experience by bringing advancement in their lifestyle.
#machinelearningapps #machinelearningdevelopers #machinelearningexpert #machinelearningexperts #expertmachinelearningservices #topmachinelearningcompanies #machinelearningdevelopmentcompany
Visit Blog- https://www.xplace.com/article/8743
#machine learning companies #top machine learning companies #machine learning development company #expert machine learning services #machine learning experts #machine learning expert
1617331066
Reinforcement learning (RL) is surely a rising field, with the huge influence from the performance of AlphaZero (the best chess engine as of now). RL is a subfield of machine learning that teaches agents to perform in an environment to maximize rewards overtime.
Among RL’s model-free methods is temporal difference (TD) learning, with SARSA and Q-learning (QL) being two of the most used algorithms. I chose to explore SARSA and QL to highlight a subtle difference between on-policy learning and off-learning, which we will discuss later in the post.
This post assumes you have basic knowledge of the agent, environment, action, and rewards within RL’s scope. A brief introduction can be found here.
The outline of this post include:
We will compare these two algorithms via the CartPole game implementation. This post’s code can be found here :QL code ,SARSA code , and the fully functioning code . (the fully-functioning code has both algorithms implemented and trained on cart pole game)
The TD learning will be a bit mathematical, but feel free to skim through and jump directly to QL and SARSA.
#reinforcement-learning #artificial-intelligence #machine-learning #deep-learning #learning
1615891741
SISGAIN is one of the top e-Learning software companies in New York, USA. Develop Education Technology based, mobile application for e-learning from SISGAIN. We Develop User Friendly Education App and Provide e-learning web portals development Service. Get Free Quote, Instant Support & End to End Solution. SISGAIN has been developing educational software and provides e-learning application development services for US & UK clients. For more information call us at +18444455767 or email us at hello@sisgain.com
#learning development companies #development of software for e-learning #top e-learning software companies #e-learning web portals #mobile applications for e-learning #e-learning product development
1593529260
In the previous blog, we looked into the fact why Few Shot Learning is essential and what are the applications of it. In this article, I will be explaining the Relation Network for Few-Shot Classification (especially for image classification) in the simplest way possible. Moreover, I will be analyzing the Relation Network in terms of:
Moreover, effectiveness will be evaluated on the accuracy, time required for training, and the number of required training parameters.
Please watch the GitHub repository to check out the implementations and keep updated with further experiments.
In few shot classification, our objective is to design a method which can identify any object images by analyzing few sample images of the same class. Let’s the take one example to understand this. Suppose Bob has a client project to design a 5 class classifier, where 5 classes can be anything and these 5 classes can even change with time. As discussed in previous blog, collecting the huge amount of data is very tedious task. Hence, in such cases, Bob will rely upon few shot classification methods where his client can give few set of example images for each classes and after that his system can perform classification young these examples with or without the need of additional training.
In general, in few shot classification four terminologies (N way, K shot, support set, and query set) are used.
At this point, someone new to this concept will have doubt regarding the need of support and query set. So, let’s understand it intuitively. Whenever humans sees any object for the first time, we get the rough idea about that object. Now, in future if we see the same object second time then we will compare it with the image stored in memory from the when we see it for the first time. This applied to all of our surroundings things whether we see, read, or hear. Similarly, to recognise new images from query set, we will provide our model a set of examples i.e., support set to compare.
And this is the basic concept behind Relation Network as well. In next sections, I will be giving the rough idea behind Relation Network and I will be performing different experiments on 102-flower dataset.
The Core idea behind Relation Network is to learn the generalized image representations for each classes using support set such that we can compare lower dimensional representation of query images with each of the class representations. And based on this comparison decide the class of each query images. Relation Network has two modules which allows us to perform above two tasks:
Training/Testing procedure:
We can define the whole procedure in just 5 steps.
Few things to know during the training is that we will use only images from the set of selective class, and during the testing, we will be using images from unseen classes. For example, from the 102-flower dataset, we will use 50% classes for training, and rest will be used for validation and testing. Moreover, in each episode, we will randomly select 5 classes to create the support and query set and follow the above 5 steps.
That is all need to know about the implementation point of view. Although the whole process is simple and easy to understand, I’ll recommend reading the published research paper, Learning to Compare: Relation Network for Few-Shot Learning, for better understanding.
#deep-learning #few-shot-learning #computer-vision #machine-learning #deep learning #deep learning