提交机器学习模型的引入

This commit is contained in:
guor
2019-11-28 18:08:39 +08:00
parent 523f7bbc97
commit 2398e7bb75
12 changed files with 290 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package com.pgmmers.radar.dal.model;
import com.pgmmers.radar.vo.model.MoldVO;
public interface MoldDal {
MoldVO get(Long id);
}

View File

@@ -0,0 +1,44 @@
package com.pgmmers.radar.dal.model.impl;
import com.pgmmers.radar.dal.model.MoldDal;
import com.pgmmers.radar.mapper.MoldMapper;
import com.pgmmers.radar.mapper.MoldParamMapper;
import com.pgmmers.radar.model.MoldPO;
import com.pgmmers.radar.model.MoldParamPO;
import com.pgmmers.radar.vo.model.MoldParamVO;
import com.pgmmers.radar.vo.model.MoldVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class MoldDalImpl implements MoldDal {
@Resource
private MoldMapper moldMapper;
@Resource
private MoldParamMapper moldParamMapper;
@Override
public MoldVO get(Long id) {
MoldVO vo = new MoldVO();
MoldPO moldPO = moldMapper.selectByPrimaryKey(id);
if (moldPO != null) {
Example example = new Example(MoldParamPO.class);
example.createCriteria().andEqualTo("moldId", id);
List<MoldParamPO> moldParamList = moldParamMapper.selectByExample(example);
List<MoldParamVO> list = moldParamList.stream().map(moldParamPO -> {
MoldParamVO moldParamVO = new MoldParamVO();
BeanUtils.copyProperties(moldParamPO, moldParamVO);
return moldParamVO;
}).collect(Collectors.toList());
BeanUtils.copyProperties(moldPO, vo);
vo.setParams(list);
return vo;
}
return null;
}
}

View File

@@ -0,0 +1,24 @@
package com.pgmmers.radar.vo.model;
import java.io.Serializable;
/**
* <p>
* 机器学习模型配置,目前只考虑输入层为离散值的情况,不考虑需要词嵌入和融入卷积层,其中
* 离散值通过表达式取数从前置流程传递过来.
* </p>
*
* @author guor
* @date 2019/11/28
*/
public class MoldParamVO implements Serializable {
private Long id;
/**
* 取数表达式
*/
private String exp;
/**
* 参数顺序,显式配置,强制有序
*/
private int order;
}

View File

@@ -0,0 +1,88 @@
package com.pgmmers.radar.vo.model;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 机器学习模型配置,定义模型文件路径和参数
* </p>
*
* @author guor
* @date 2019/11/28
*/
public class MoldVO implements Serializable {
/**
* 自增ID主键
*/
private Long id;
/**
* 模型名称
*/
private String name;
/**
* 输入层参数的key
*/
private String feed;
/**
* 模型参数定义,需要注意参数顺序,改变顺序会使模型调用出错或者失效
*/
private List<MoldParamVO> params;
/**
* 模型文件路径
*/
private String path;
/**
* 模型更新时间
*/
private Date updateDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFeed() {
return feed;
}
public void setFeed(String feed) {
this.feed = feed;
}
public List<MoldParamVO> getParams() {
return params;
}
public void setParams(List<MoldParamVO> params) {
this.params = params;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
}

View File

@@ -0,0 +1,7 @@
package com.pgmmers.radar.mapper;
import com.pgmmers.radar.model.MoldPO;
import tk.mybatis.mapper.common.Mapper;
public interface MoldMapper extends Mapper<MoldPO> {
}

View File

@@ -0,0 +1,7 @@
package com.pgmmers.radar.mapper;
import com.pgmmers.radar.model.MoldParamPO;
import tk.mybatis.mapper.common.Mapper;
public interface MoldParamMapper extends Mapper<MoldParamPO> {
}

View File

@@ -0,0 +1,28 @@
package com.pgmmers.radar.model;
import javax.persistence.Table;
import java.util.Date;
@Table(name = "engine_mold")
public class MoldPO {
/**
* 自增ID主键
*/
private Long id;
/**
* 模型名称
*/
private String name;
/**
* 输入层参数的key
*/
private String feed;
/**
* 模型文件路径
*/
private String path;
/**
* 模型更新时间
*/
private Date updateDate;
}

View File

@@ -0,0 +1,17 @@
package com.pgmmers.radar.model;
import javax.persistence.Table;
@Table(name = "engine_mold_param")
public class MoldParamPO {
private Long id;
private Long moldId;
/**
* 取数表达式
*/
private String exp;
/**
* 参数顺序,显式配置,强制有序
*/
private int order;
}

View File

@@ -0,0 +1,19 @@
package com.pgmmers.radar.service.impl.dnn;
import com.pgmmers.radar.service.dnn.Estimator;
import com.pgmmers.radar.service.model.MoldService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
@Component
public class TensorFlowEstimator implements Estimator {
@Resource
private MoldService moldService;
@Override
public double predict(Long modelId, Map<String, Map<String, ?>> data) {
return 0;
}
}

View File

@@ -0,0 +1,19 @@
package com.pgmmers.radar.service.impl.model;
import com.pgmmers.radar.dal.model.MoldDal;
import com.pgmmers.radar.service.model.MoldService;
import com.pgmmers.radar.vo.model.MoldVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class MoldServiceImpl implements MoldService {
@Resource
private MoldDal moldDal;
@Override
public MoldVO get(Long id) {
return moldDal.get(id);
}
}

View File

@@ -0,0 +1,23 @@
package com.pgmmers.radar.service.dnn;
import java.util.Map;
/**
* <p>
* 机器学习模型执行器接口
* </p>
* <p>
* 该接口内置TensorFlow实现目前版本只考虑输入层为离散值的情况不考虑词嵌入和融入卷积层其中
* 离散值通过表达式取数从前置流程传递过来,模型的预测结果为事件评分。
* </p>
* <p>
* 模型抽象y=f(x)
* </p>
*
* @author guor
* @date 2019/11/28
*/
public interface Estimator {
double predict(Long modelId, Map<String, Map<String, ?>> data);
}

View File

@@ -0,0 +1,7 @@
package com.pgmmers.radar.service.model;
import com.pgmmers.radar.vo.model.MoldVO;
public interface MoldService {
MoldVO get(Long id);
}