Download presentation
Presentation is loading. Please wait.
1
3. .NET for Data Science and AI
.NET and .NET Core 3. .NET for Data Science and AI Pan Wuming 2017
2
References M. Gabbrielli, S. Martini, Programming Languages: Principles and Paradigms, Springer-Verlag, 2010 Microsoft Docs
3
MS is an established AI company!
Topics .NET for Machine Learning and AI F#: Functions as First-Class Values Application and Reduction in F# F# Language Oriented Programming MS is an established AI company!
4
.NET for Machine Learning and AI
Build .NET apps with deep learning libraries like CNTK, Tensorflow and Accord.NET. Accord.NET is completely written in C#. Azure cognitive services: Vision, Knowledge, Language, Speech and Search Azure Machine Learning F# Functional programming To develop GPU-accelerated computing applications on .NET, combining the CUDA with Microsoft’s F#.
5
F# Functional Programming for Data Science and AI
“Data science seeks actionable and consistent pattern for predictive uses. This practical engineering goal takes data science beyond traditional analytics. Now the data in those disciplines and applied fields that lacked solid theories, like health science and social science, could be sought and utilized to generate powerful predictive models.” F# Functional programming to focus on function composition F# Type provider to eliminate the barrier of including a source of information into a program That is the need to represent that information as types, properties, and methods for use in a programming language environment. Using F# Units of Measure helps prevent programming errors F# Language Oriented Programming simplifies the integration of Symbolic AI Programming in .NET Platform.
6
Functions as First-Class Values
7
Typical measures of first-class status
Can you bind functions to identifiers? That is, can you give them names? Can you store functions in data structures, such as in a list? Can you pass a function as an argument in a function call? Can you return a function from a function call? The last two measures define what are known as higher-order operations or higher-order functions.
8
let Bindings Z ?
9
Types for Type Inference
Types are used to abstract programming Type Inference Is to collect constraints from the way you use names Is to automatically generalize your code Automatic generalization is applied when a let or member definition doesn’t fully constrain the types of inputs or outputs.
10
Type Inference You do not have to specify the types of F# constructs except when the compiler cannot conclusively deduce the type Give the Value a Name F# uses let bindings to bind names to values: F# binds function names to lambda expressions: let <identifier> = <value> let num = 10 let str = "F#" The type of a function value is specified by using the -> token. Hence squareIt2 has type: int -> int let <function-name> = <lambda-expression> let squareIt = fun n -> n * n //more concise syntax let squareIt2 n = n * n
11
Store the Value in a Data Structure
// Lists. let integerList = [ 1; 2; 3; 4; 5; 6; 7 ] let stringList = [ "one"; "two"; "three" ] // In F#, functions can be stored in a list, as long as the functions have the same signature. let squareIt = fun n -> n * n let doubleIt = fun n -> 2 * n let funList = [ squareIt; doubleIt ] // Tuples. // A tuple does not require its elements to be of the same type. let moreMixedTuple = ( num, "two", 3.3, squareIt )
13
Pass a function as an argument
In the simplest cases, it is similar to using delegate type as parameter type in C# code Passing a method call as an Argument in C# code It is the common abstractions in F#. That is, you focus on function compositions than the implementation of argument function. let applyIt = fun op arg -> op arg System.Console.WriteLine(applyIt squareIt num) System.Console.WriteLine(squareIt num)
14
Return a function from a function call
It is to define a new function from a function call, and to bind a name to the new function. the implicit currying in F# function declarations
15
let compose = fun op1 op2 -> fun n -> op1 (op2 n) // To clarify what you are returning, use a nested let expression: let compose2 = let funToReturn = fun n -> funToReturn
16
Higher-order functions
A function that takes a function as an argument, or delivers one as a result, is referred to as a higher order function. Currying
17
Currying Currying is a process that transforms a function that has more than one parameter into a series of embedded functions, each of which has a single parameter. In F#, functions that have more than one parameter are inherently curried.
18
let compose4 op1 op2 n = op1 (op2 n)
//the type of function value compose4 is: op1:('a -> 'b) -> op2:('c -> 'a) -> n:'c -> 'b let squareIt = fun n -> n * n let doubleIt = fun n -> 2 * n System.Console.WriteLine(((compose4 doubleIt) squareIt) 3) System.Console.WriteLine((compose4 doubleIt squareIt) 3) System.Console.WriteLine(compose4 doubleIt squareIt 3);; //Each of them returns and displays 18.
19
Functional Programming
Computation proceeds by rewriting functions and not by modifying the state Immutable values are values that cannot be changed throughout the course of a program's execution. It does not need the concept of memery Referential Transparency An expression always denotes the same value in its context. Whenever a function f is applied to the argument value arg it will produce the same output no matter what the overall state of the computation is.
20
The λ-calculus Backus Naur normal form (BNF)
λ is the abstraction operator Grammar:
21
free variables and bound variables
Substitution free variables and bound variables
22
Computation: β Reduction
Problem: ?
23
Expressiveness of the λ-calculus
The λ-calculus is a Turing-complete formalism It is possible to encode the natural numbers as λ-terms a λ-term n is associated with the number n To every computable function, f , there corresponds a λ-term Mf which computes f : if f (n) = m, then Mf n→m.
24
The Computing View of Functional Languages
To ease the specification of sets and recursive functions To concentrate on specifying input–output relation a programmer should specify what to compute, rather than how, where, and when. No statements Programmers put the burden of finding an efficient computation order on the compiler.
25
Overview of handling functional language aspects
The blocks are expressed by their indentation.
26
Structure of a functional compiler
27
Lazy evaluation A subexpression will only be evaluated when its value is needed for the progress of the computation. Eager evaluation
28
The λ notation is renamed as fun
Abstraction in F# The λ notation is renamed as fun Function as value To bind an identifier to the value Let expressions
29
Application and Reduction in F#
30
Defining Recursive Functions
A recursive function is simply one that can call itself as part of its own definition. Recursive functions are introduced by let rec.
31
The execution of factorial 5
32
F# Language Oriented Programming
全之尽之,然后学者。 ——《荀子》 Symbolic AI was the dominant paradigm of AI research from the mid-1950s until the late 1980s. Symbolic AI has programming convention for general problem solving Symbolic AI use clearly represented knowledge, while Machine Learn use data to generate some kind of black-box models. By F#, you can define a formal language, “language type”, and instantiate facts, knowledge, and theories of that type, then apply thinking rules on them. These characteristics are very different than OO programming. Which is also supported by Swift, the most popular iOS programming language. There is no ability barrier between symbolic AI and machine learning!
33
Data Science Machine Learning F# AI
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.