HttpClient 使用简单案例(scala 版本)

驾驭Scala的网络之力:HTTP客户端与服务器实战指南 Scala,以其强大的函数式编程特性和类型系统,为构建高效、可靠的HTTP客户端和服务器提供了丰富的工具和库。本文将深入探讨如何在Scala中使用HTTP客户端和服务器,包括使用流行的库如Play Framework、Akka HTTP等,以及如何编写高效、安全的网络应用。本文详细介绍了如何在Scala中使用这些工具,包括编写服务器和客户端的示例代码、安全通信的考虑以及性能优化的建议。通过本文的介绍,你应该能够理解如何在Scala中使用HTTP客户端和服务器,并能够将其应用到实际的网络编程中。 阅读详情

HttpClient 使用简单案例(scala 版本)

1. 背景

1.1 概述

  1. 在常见的客户端服务器模型中,最开始是BS模型,也就是browser和server模型,因为最开始都是电脑,浏览器访问占据主流地位。阿里巴巴,京东都是先从网站做起的。
  2. 之后的模型变成了cs模型,client客户端,server服务器。这是由于互联网兴起,各种移动客户端流量开始占据主流,如手机,平板,甚至手表,汽车都可以访问网络。
  3. 在这个过程中,作为企业级开发语言主流的java,也出现了很多网络请求库,其中比较有历史的就是httpclient这个库。比较悠久,但目前实际在安卓开发中,早就已经由谷歌提出了新的网络库选择,在安卓6.0之后,谷歌移除了httpclient的api接口了。
  4. 本文只是处于怀旧情况,回忆一下httpclient的简单使用
  5. 实际安卓开发中,目前可以有
  • HttpClient 这是底层的库之一,但目前谷歌官方不建议再在安卓开发中使用
  • HttpURLConnection ,这是sun公司编写的底层网络库,api较少,谷歌建议使用这种底层请求库
  • Volley,本身是基于底层请求库做了封装。在Android 2.3及以上的版本,使用的是HttpURLConnection,而在Android 2.2及以下版本,使用的是HttpClient。HurlStack和HttpClientStack分别对应HttpURLConnection 和HttpClient
  • OkHttp,okhttp是square公司开发的网络框架。目前使用较多的网络库之一。Android 4.4后,HttpURLConnection底层实现使用的就是OkHttp
  • Retrofit,Retrofit与okhttp一样出自于Square公司。Retrofit是一个封装的网络框架,底层网络框架使用的是OkHttp(Retrofit 2.0 开始不支持其他底层网络框架)。

1.2 官网介绍等

  • http://hc.apache.org/httpclient-3.x/
    在这里插入图片描述
  • github
    https://github.com/apache/httpcomponents-client
    在这里插入图片描述
  • maven
    https://mvnrepository.com/search?q=httpclient
    在这里插入图片描述
    在这里插入图片描述

2. 代码

  1. 环境准备
  • maven 3.6.3
  • idea 2020
  • jdk 1.8
  • scala 2.12.12
  • pom文件
<!-- 定义了一些常量 -->
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <scala.version>2.12.10</scala.version>
        <spark.version>3.0.1</spark.version>
        <hbase.version>2.2.5</hbase.version>
        <hadoop.version>3.2.1</hadoop.version>
        <encoding>UTF-8</encoding>
    </properties>

    <dependencies>
        <!-- 导入scala的依赖 -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
            <!-- 编译时会引入依赖,打包是不引入依赖 -->
            <!--            <scope>provided</scope>-->
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.12</version>
        </dependency>


        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.12</artifactId>
            <version>${spark.version}</version>
            <!-- 编译时会引入依赖,打包是不引入依赖 -->
            <!--            <scope>provided</scope>-->
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.73</version>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <!-- 编译scala的插件 -->
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                <!-- 编译java的插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- 打jar插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
  1. 演示代码
package com.doit.day07


import com.alibaba.fastjson.{JSON, JSONObject}
import org.apache.http.HttpEntity
import org.apache.http.client.methods.{CloseableHttpResponse, HttpGet}
import org.apache.http.impl.client.{CloseableHttpClient, HttpClients}
import org.apache.http.util.EntityUtils

object HttpClientTest {
  def main(args: Array[String]): Unit = {

    // 创建客户端对象
    val httpClient: CloseableHttpClient = HttpClients.createDefault()

    val longitude = 119.3
    val latitude = 40

    // 创建一个httpGet,这里面拼接域名,path,以及参数,因为是get类型,参数都在url里面
    // 这里使用的高德地图开放出来的API接口进行演示
    val httpGet = new HttpGet(s"https://restapi.amap.com/v3/geocode/regeo?&location=$longitude,$latitude&key=4924f7ef5c86a278f5500851541cdcff")

    // 执行请求,获取返回信息对象
    val response: CloseableHttpResponse = httpClient.execute(httpGet)

    // 获取返回信息对象中实体对象
    val entity: HttpEntity = response.getEntity

    // http状态码,2xx,3xx,4xx,5xx,
    // 2开头一般表明请求成功如200,3开头一般是重定向,4开头一般是请求参数错误如404标识找不到
    // 5开头一般是服务器错误
    if(response.getStatusLine.getStatusCode == 200) {
      // 将返回结果中数据转换为字符串
      val resultStr: String = EntityUtils.toString(entity)

      // 将字符串转换为JSON对象
      val jsonObj: JSONObject = JSON.parseObject(resultStr)

      // 根据API说明文档字段,进行数据解析
      val regeocode: JSONObject = jsonObj.getJSONObject("regeocode")

      // 判空处理,防止异常
      if(regeocode != null && regeocode.isEmpty == false) {
        val address: JSONObject = regeocode.getJSONObject("addressComponent")

        println(address)
      }
    }

    // 关闭请求
    httpClient.close()
  }
}
scalaj-http:HttpURLConnection的简单scala包装器。 包含OAuth 简体Http 这是Scala的功能齐全的http客户端,其中包装了 特征: 零依赖 针对Scala 2.10、2.11、2.12和2.13-M3交叉编译 OAuth v1请求签名 从服务器自动支持gzip和deflate编码 易于添加查询字符串或表单参数。 URL编码已为您处理。 分段文件上传 非功能: 异步执行 该库是线程安全的。 HttpRequest和HttpResponse是不可变的。 因此,应该很容易将其包装在您选择的执行框架中。 适用于Google AppEngine和Android环境。 注意: 2.xx是新的主要版本,在语法和行为上均与0.xx版本不同。 以前的 立即下载

相关推荐

sslcontext-kickstart::locked_with_key:一个轻量级的高级库,用于基于SSLContext或其他属性(例如TrustManager,KeyManager或Trusted Certificates)配置http客户端,以通过SSL TLS进行通信,以进行SSLFactory提供的单向身份验证或双向身份验证。 通过示例支持基于Java,Scala和Kotlin的客户端。 可用的客户端示例包括:Apache HttpClient,OkHttp,Spring RestTempla

SSLContext Kickstart :locked_with_key: 使用以下方法安装库: 用安装 < dependency> < groupId>io.github.hakky54</ groupId> < artifactId>sslcontext-kickstart</ artifactId> < version>6.2.0</ version> </ dependency> 使用Gradle安装 implementation ' io.github.hakky54:sslcontext-kickstart:6.2.0 ' 使用Scala SBT安装 libraryDe

Scala 通过HttpClients发送get和post请求

Scala 通过HttpClients发送get和post请求 由于之前的工程代码都是使用Scala开发的,而最近工作中涉及到一个新功能需要发送post请求后端接口,今把如何使用HttpClients做个笔记。 get请求 def getResponse(url: String, header: String = null): String = { val httpClient = Htt...

清晨随笔 1万+

centos7安装db2 version11.1

centos7安装db2 version11.1

AKA石头 1062

Scala Http 请求调用 - scalaj-http

Simplified Http This is a fully featured http client for Scala which wrapsjava.net.HttpURLConnection Features: Zero dependencies Cross compiled for Scala 2.10, 2.11, 2.12, and 2.13-M3 OAuth v1...

weixin_30555753的博客 2118

基于Codex Skill的抖音爆款分析与带货视频自动化生成实战

这次我们来看一个基于 Codex 的自动化内容创作项目。核心是利用 Codex 平台的能力,通过自定义的 Skill(技能)来拆解抖音爆款博主的视频模式,并自动生成自己的带货视频。对于内容创作者、电商运营或对短视频自动化感兴趣的技术开发者来说,这是一个将大语言模型(LLM)能力与具体业务场景深度结合的实战案例。 项目的核心价值在于流程自动化。它试图解决一个常见痛点:分析爆款视频的脚本结构、话术、节奏需要大量人工,而模仿创作又耗时费力。通过 Codex 的 Skill 机制,可以将“分析”和“生成”这两个环节

weixin_30420305的博客 383

深入理解梅尔刻度、梅尔滤波器组和梅尔时频谱图

读取一段音频,使用短时傅里叶变换,得到普通的时频谱图,然后绘制梅尔滤波器组,值得注意的是,librosa的梅尔滤波器组函数还带有权重归一化功能,即对一个三角形滤波器的每个权重,都除以该三角形的面积,如果不希望进行该归一化,设置参数。从公式可见,对数部分可以以自然对数为底数,也可以以10为底数,不同的底数对应不同的系数,要确定当前的系数,只需要代入(1000Hz, 1000mel)即可。其中,m是当前滤波器的序号,表征了当前的时间段,k是当前频率的序号,表征了当前正在对哪一频率的。

DEDSEC_Roger的博客 1万+

Scala-2-通过HttpClients发送get和post请求

(1)通过sbt安装依赖 libraryDependencies += “org.apache.httpcomponents” % “httpclient” % “4.5.3” libraryDependencies += “org.apache.httpcomponents” % “httpcore” % “4.4.9” libraryDependencies += “com.alibaba” % “fastjson” % “1.2.32” (2)基于Flask的服务端 from flask import

qq_20466211的博客 1627

python操作git推送自己分支并合并主分支(持续优化该工具)

python git

qq_44707265的博客 862

使用Scala和Apache HttpClient构建代理爬虫,抓取小红书网站图片数据

通过本文,我们学习了如何使用Scala和Apache HttpClient构建一个简单的代理爬虫,用于从小红书网站抓取图片数据。在实际应用中,我们可能需要进一步处理获取的图片数据,比如保存到本地文件或进行其他操作。在使用爬虫时,请务必遵守网站的使用规定,并尊重数据隐私和法律法规。在网络爬虫领域,使用代理是一种常见的技术,可以帮助我们绕过访问限制,保护我们的隐私,并提高爬取效率。本文将介绍如何使用Scala编写一个简单的代理爬虫,使用Apache HttpClient库从小红书网站获取图片数据。

D0126_的博客 513

部署与可视化系统:零基础到精通:LabVIEW 调用 YOLO 动态链接库(DLL)的保姆级视觉检测系统融合实战

LabVIEW与YOLO26深度集成:工业视觉检测新范式 本文揭示了LabVIEW与最新YOLO26模型深度集成的创新方案,通过C++封装ONNX Runtime为DLL,在LabVIEW中实现端到端视觉检测。核心突破点包括: 技术选型:对比YOLOv5/YOLOv8/YOLO26性能,YOLO26在CPU推理速度提升43%,支持NMS-Free端到端推理 部署架构:提供ONNX Runtime C++ API和TensorRT两种DLL封装路径,适配不同硬件环境 工程实现:详细展示从PyTorch模型导出

ZXSXJ的博客 282

自注意力机制(SelfAttention Mechanism)原理与代码实战案例讲解

自注意力机制(Self-Attention Mechanism)原理与代码实战案例讲解 作者:禅与计算机程序设计艺术 / Zen and the Art of Computer Programming 1. 背景介绍

AI天才研究院 1290

Requests-Scala与JDK 11 HttpClient:底层实现原理分析

Requests-Scala是一个Scala语言实现的HTTP客户端库,它移植自Python的Requests库,以灵活、直观且易于使用的特点著称。该库底层基于JDK 11引入的HttpClient API构建,通过封装和优化,为Scala开发者提供了更加友好的HTTP请求接口。本文将深入分析Requests-Scala如何与JDK 11 HttpClient协同工作,揭示其底层实现原理和性能优化

gitblog_00853的博客 980

流程图详解Transformer最核心的多头注意力机制,QKV流向清晰明了

本文详细讲解了Transformer模型中的多头注意力机制(Multi-head Attention)。通过类比多人评估同一事物的不同视角,说明多头机制能综合多个注意力权重获得更有效的输出。文章逐步推导了多头注意力的计算过程:将输入矩阵X(4×512维)分别与8组Q、K、V权重矩阵相乘,得到8组head(每组4×64维),拼接后经Wo矩阵变换恢复为4×512维输出。整个过程涉及37个待训练参数矩阵(1个Wo、8组Wq/Wk/Wv)。该机制通过并行计算多个注意力头,能更全面捕捉输入特征间的复杂关系。

人工智能研究所的博客 259

Scala结合HttpClient实现简单的爬虫

Scala是一种“面向对象的函数式”语言。对于不熟悉函数式编程风格的人来说适应Scala确实需要一段时间。也只有多看多写了吧。以下是用Scala结合HttpClient实现的一个简单的爬虫小程序。 package com.eric.crawler import java.io.{BufferedReader, InputStream, InputStreamReader} import co

biww620的博客 3213

从零实战:模拟Soul/陌陌附近的人接口爬虫(设备指纹·加密逆向·动态代理全解)

在移动互联网流量见顶的今天,LBS(基于位置的服务)社交平台——尤其是Soul和陌陌——依然掌握着海量高活用户的地理位置画像、兴趣标签、在线活跃时段等敏感数据。对于市场调研、流量运营、甚至是城市热力分析而言,“附近的人”接口是一个极具价值的入口。然而,这两款App均采用全参数加密 + 设备指纹风控 + WAF动态防御的三重护城河。直接使用Requests库调用公开API无异于以卵击石。本文将从逆向工程视角出发,完整还原一套可用的附近人信息采集方案,涵盖:抓包与流量分析(绕过SSL Pinning)

2201_76125261的博客 211

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Apache HttpClient库编写的Scala程序

方法中,程序首先定义服务器的主机名和端口号,然后创建一个HttpClient对象,并设置其使用服务器。然后,程序创建一个HttpHead对象,并使用HttpClient对象执行该对象以获取网页的头部信息。然后,程序检查返回的状态码,如果状态码为200,则表示请求成功,程序获取响应实体,并将其内容打印到控制台。程序首先导入所需的Apache HttpClient库和HttpHost,HttpClient和HttpHead类。然后,程序创建一个名为。的类,并在其中定义一个名为。

weixin_73725158的博客 855

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

A Scala REST client using the Apache HttpClient library

A Scala REST client using the Apache HttpClient library By Alvin Alexander. Last updated: May 4, 2015 After writing a Java REST (RESTful) client using Apache HttpClient, I turned around and modif

w_j_w2010的博客 1104

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

OpenCore Legacy Patcher 实操:旧 Mac 装新版 macOS,2–4 小时全流程

OpenCore Legacy Patcher(下称 OCLP)是个开源 Python 工具,把苹果已停止官方支持的 macOS 11 至最新版 Tahoe,装进 2008 年以后的 Intel 老 Mac。原理就两件事:引导阶段绕过机型限制,进系统后修补显卡、Wi-Fi 等驱动。全程不碰固件,整套流程可回退。 最大的前置条件:机型编号必须在支持列表内。苹果菜单→「关于本机」里查 `MacBoo

gitblog_00536的博客 678

Requests-Scala:Scala开发者的终极HTTP客户端解决方案

Requests-Scala是Python知名HTTP客户端库Requests的Scala移植版本,为Scala开发者提供了一种灵活、直观且易于使用的HTTP客户端解决方案。如果你正在寻找一个简单高效的Scala HTTP客户端库,Requests-Scala绝对是你的最佳选择!🚀 ## 为什么选择Requests-Scala? 在Scala生态系统中,HTTP客户端库众多,如Akka-ht

gitblog_00124的博客 300

利用Scala与Apache HttpClient实现网络音频流的抓取

在当今数字化时代,网络数据的抓取和处理已成为许多应用程序和服务的重要组成部分。本文将介绍如何利用Scala编程语言结合Apache HttpClient工具库实现网络音频流的抓取。通过本文,读者将学习如何利用强大的Scala语言和Apache HttpClient库来抓取网络上的音频数据,以及如何运用这些技术实现数据获取和分析。Scala是一种多范式编程语言,结合了面向对象和函数式编程的特点。它运行在Java虚拟机上,具有强大的表达能力和优秀的可扩展性。

Z_suger7的博客 1097

scala http get请求

import org.apache.http.client.methods.{CloseableHttpResponse, HttpGet} import org.apache.http.impl.client.{CloseableHttpClient, HttpClients} import org.apache.http.util.EntityUtils object getDemo extends App { val url = "https://git-scm.com/docs/git-sta

鸭梨的博客 836

DSH Desktop 插件市场快速上手:一键安装到底是怎么过校验的

如果你正在使用 DSH Desktop,并且一直靠手动命令管理 DeepSeek Harness 插件,那么内置的 DSH Community Market(插件市场)就是你做插件发现、一键安装与跨市场卸载的第一入口。这份指南不按按钮顺序带你点,而是沿着「来源 → 标准化 → 校验 → 精确安装 → 清单卸载」这条完整链路,讲清楚它在界面背后替你做了什么。不管插件从哪个渠道装进来,都能统一查看、统

gitblog_00220的博客 939

Scala,Spark依赖jar包冲突解决方法

问题背景: 在提交任务运行时,报了如下错误: Caused by: java.lang.BootstrapMethodError: call site initialization exception … Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type interface org.apache.http.Header; not a subtype of implementation type inter

Code_LT的博客 4511

用scala语言,用HttpClient读取数据,存入阿里云服务器上的HBase中

废话少说,直接上代码。 val now: Date = new Date() val gt = now.getTime var time = gt + "" val client: HttpClient = new HttpClient val method: GetMethod = new GetMethod(url) client.exec...

tang_xiaotang的博客 682

OkHttp的基本使用——替代Apache HttpClient

https://www.jianshu.com/p/543b4766d25e

didixiao_的博客 721

python zio_如何使用ZIO和Http4s创建简单的API客户端

python zio 与巴西朋友讨论了我们国家的情况后,我们意识到查找有关公共支出的信息有多么困难,并且在有可用信息的情况下,很难对此进行推理。 我们决定联合起来,探索巴西政府提供的一些数据,以期提供一种更简便的方法来可视化和了解如何使用公共资源。 起点是:找到一些数据进行分析,这些数据相对容易收集(至少从开发人员的角度而言)。 最好的候选者是Portal daTransparência (...

编程故事的地方 800
上一篇: 服务器机房中的高科技细节
下一篇: Spark RDD案例(四)IP和地理位置映射统计
闻香识代码
博客等级 码龄12年 314粉丝 223原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值