diff --git a/.vscode/settings.json b/.vscode/settings.json index 163e89c7..0850cfbd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,11 @@ "python.linting.enabled": true, "python.pythonPath": "C:\\Python\\python.exe", "files.associations": { - "xstring": "cpp" + "xstring": "cpp", + "deque": "cpp", + "initializer_list": "cpp", + "list": "cpp", + "vector": "cpp", + "xutility": "cpp" } } \ No newline at end of file diff --git a/C++/标准库/11 lambda表达式.md b/C++/标准库/11 lambda表达式.md index e69de29b..dbb6173a 100644 --- a/C++/标准库/11 lambda表达式.md +++ b/C++/标准库/11 lambda表达式.md @@ -0,0 +1,124 @@ +# lambda表达式 + + +## 1 简介 + +### 对象分类 + +对象的分类 + +* 基础类型的对象 +* 复合类型的对象 +* 类类型的对象 +* 函数对象 + +### 可调用对象 +可调用对象是可以使用函数调用运算符`()`的对象。 +* 函数 +* 函数指针 +* 重载了函数调用运算符的类 +* lambda表达式 + + +## 2 使用 + +### Lambda表达式定义 + +* 形式。仅仅是形式上不同的函数。capture list捕获列表是外部的局部变量的列表,捕获后可以在函数内部使用。 +``` +[capture list](parameter list) -> return type {function body} +``` + +* 没有参数和返回值的lambda表达式 +```C++ +auto l=[]{ + cout<<"hello world"<int{cout< words={"abc","a","bc","feiao"}; + int sz =4; + auto wc = find_if(words.begin(),words.end(), + [sz](const string &a){ + return a.size()>=sz; + } + ); + cout<<(*wc)<=sz2){ + cout<int{ + if(i<0)return -i; + else return i; + } +); +``` + +## 3 bind 参数绑定 + +lambda 表达式通常只在一个地方使用的简单操作。如果需要在多个地方使用相同的操作,通常定义一个函数,而不是多次编写相同的lambda表达式。 + +bind函数适配器,接受一个函数对象,生成一个行的可调用的对象。 +```C++ +auto newCallable = bind(callable,arg_list); +auto g = bind(f,a,b,_2,c,_1); +``` + +* `_1,_2`分别表示新函数g的第一个和第二参数。 \ No newline at end of file diff --git a/C++/标准库/11.cpp b/C++/标准库/11.cpp new file mode 100644 index 00000000..4ec7f6e6 --- /dev/null +++ b/C++/标准库/11.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +int main(){ + +//使用find_if和lambda表达式 + vector words={"abc","a","bc","feiao"}; + int sz =4; + auto wc = find_if(words.begin(),words.end(), + [&sz](const string &a){ + return a.size()>=sz; + } + ); + cout<<(*wc)<=sz2){ + cout< +#include +#include +#include + +using namespace std; + +int main(){ + + list lst ={1,2,3,4}; + list lst2,lst3; + //反向一个列表 + copy(lst.cbegin(),lst.cend(),front_inserter(lst2)); + //正向一个列表 + copy(lst.cbegin(),lst.cend(),inserter(lst3,lst3.begin())); + return 0; +} +``` + +### 流迭代器 + +接受输入输出流,使用迭代器的方式读取数据。 + + + +* istream_iterator:读取输入流 + + +![](2021-03-06-14-50-48.png) + +``` + /* + * 读取数据的三种方法 + * 直接使用输入输出流iostream + * 使用字符串方法封装getline + * 使用迭代器读取输入输出流istream_iterator/ostream_iterator + */ + istream_iterator in_iter(cin);//从cin读取数据 + istream_iterator eof;//尾后迭代器 + istringstream in_string("hello world"); + istream_iterator str_it(in_string);//字符串流迭代器 + + int a =0; + a = *in_iter; + cout< +#include +#include +#include +#include + +using namespace std; + +int main(){ + + list lst ={1,2,3,4}; + list lst2,lst3; + //反向一个列表 + copy(lst.cbegin(),lst.cend(),front_inserter(lst2)); + //正向一个列表 + copy(lst.cbegin(),lst.cend(),inserter(lst3,lst3.begin())); + + /* + * 读取数据的三种方法 + * 直接使用输入输出流iostream + * 使用字符串方法封装getline + * 使用迭代器读取输入输出流istream_iterator/ostream_iterator + */ + istream_iterator in_iter(cin);//从cin读取数据 + istream_iterator eof;//尾后迭代器 + istringstream in_string("hello world"); + istream_iterator str_it(in_string);//字符串流迭代器 + + int a =0; + a = *in_iter; + cout< &word){ +void unique_sort(vector &words){ sort(words.begin(),words.end()); auto end_unique = unique(words.begin(),words.end()); words.erase(end_unique,words.end()); @@ -18,7 +18,14 @@ int main(){ vector n{4,2,5,2,5,6,7}; for(int m :n){ - cout< Human-AI interaction -人没有绝对的主导权 - -## Human-Agent Collective - -对人工智能的支持与反对,引发对人工智能能利弊的思考。 - -人与AI组成的共生态。 -### 生态特点 -* flexible autonomy 要有灵活的自主性。 -autonomously whitout reference to their owner -human in/over/out of the loop - -* agile teaming -dynamically合作方式动态变化 - -* incentive enginnering - -* accountable informationg infrastructure -可以去解释原因,人能理解的结果。可解释AI,能够满足人的逻辑的结果的解释。能够对AI最优解提供具有说服力的解释。这也作为与人类狗同的一部分。 - -### Ethical AI vs. Human-Agent Collective对比 -人工智能伦理学与智能体生态 -伦理学衡量一件事的维度:数量、规则、价值。 - -面对道德问题时,如何设计系统。 - -DP 差分隐私保护。一种隐藏数据但能保重同态分布的方案。 - -## Collective Ethical Decision-making - -多agent网络信任传递 - -分工(不同构)agent - -联邦学习-把最好的数据以最快的速度拿出来。 - -多智能体-对抗->优化最后的解释。 - - - -## 案例1-劝说别人 - -生成短视频在淘宝上买东西。 - -wundt curve刺激节奏曲线。包括情绪、 - -利用9张图生成短视频。 - -## 案例2-医学系统 - -channel 诊断。初步分析病因,将病人分配给具体领域的专家。 - - -## 案例3-超时招聘 - -分布式训练模型,用于选择合适的临时工。 - - - -value senesitive design -用来发现潜在的价值。 - diff --git a/工作日志/2021年2月27日-三月份计划.md b/工作日志/2021年2月27日-三月份计划.md index b8ea5123..ec6d8ade 100644 --- a/工作日志/2021年2月27日-三月份计划.md +++ b/工作日志/2021年2月27日-三月份计划.md @@ -11,8 +11,8 @@ - 知识复习——语言 - C++(primer) - 基础语法√ - - 面向对象 - 标准库 STL + - 面向对象 - 设计模式(有道云笔记,gitee 设计模式库,书) - effective 系列 - 系列视频